diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb new file mode 100644 index 0000000..733485b --- /dev/null +++ b/app/controllers/albums_controller.rb @@ -0,0 +1,32 @@ +class AlbumsController < ApplicationController + def index + @album = Album.all + if params['title'].present? + @album = @album.where("title LIKE ?", "%#{params['title']}%") + end + end + + def show + @album = Album.find(params[:id]) + end + + def new + @album = Album.new + end + + def create + @album = Album.new(album_params) + if @album.save + redirect_to @album + else + render :new + end + end + + private + + def album_params + params.require(:album).permit(:title) + end + +end diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index c4dccc0..9d92fd3 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -1,5 +1,32 @@ class ArtistsController < ApplicationController def index - @consulta = Artist.all + @artist = Artist.all + if params['name'].present? + @artist = @artist.where("name LIKE ?", "%#{params['name']}%") + end end + + def show + @artist = Artist.find(params[:id]).albums + end + + def new + @artist = Artist.new + end + + def create + @artist = Artist.new(artist_params) + if @artist.save + redirect_to @artist + else + render :new + end + end + + private + + def artist_params + params.require(:artist).permit(:name) + end + end diff --git a/app/controllers/genres_controller.rb b/app/controllers/genres_controller.rb new file mode 100644 index 0000000..9f305de --- /dev/null +++ b/app/controllers/genres_controller.rb @@ -0,0 +1,63 @@ +class GenresController < ApplicationController + def index + @genre = Genre.all + if params['name'].present? + @genre = @genre.where("name LIKE ?", "%#{params['name']}%") + end + end + + def show + @genre = Genre.find(params[:id]) + end + + def new + @genre = Genre.new + end + + def create + @genre = Genre.new(genre_params) + if @genre.save + redirect_to @genre + else + render :new + end + end + + private + + def genre_params + params.require(:genre).permit(:name) + end + +endclass GenresController < ApplicationController + def index + @genre = Genre.all + if params['name'].present? + @genre = @genre.where("name LIKE ?", "%#{params['name']}%") + end + end + + def show + @genre = Genre.find(params[:id]) + end + + def new + @genre = Genre.new + end + + def create + @genre = Genre.new(genre_params) + if @genre.save + redirect_to @genre + else + render :new + end + end + + private + + def genre_params + params.require(:genre).permit(:name) + end + +end \ No newline at end of file diff --git a/app/controllers/tracks_controller.rb b/app/controllers/tracks_controller.rb new file mode 100644 index 0000000..2344a69 --- /dev/null +++ b/app/controllers/tracks_controller.rb @@ -0,0 +1,13 @@ +class TracksController < ApplicationController + def index + @tracks = Track.all + if params['name'].present? + @tracks = @tracks.where("name LIKE ?", "%#{params['name']}%") + end + end + + def show + @tracks = Track.find(params[:id]) + end + +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..6ef238a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,5 @@ module ApplicationHelper + def format(date) + date.strftime("%d/%m/%y %H:%M") + end end diff --git a/app/models/genre.rb b/app/models/genre.rb index 3fc7d25..a032523 100644 --- a/app/models/genre.rb +++ b/app/models/genre.rb @@ -1,5 +1,5 @@ class Genre < ApplicationRecord has_many :tracks - + scope :filtrar, ->(name) { where("name LIKE ?", "%#{name}%") if name.present? } validates_presence_of :name end diff --git a/app/views/albums/index.html.erb b/app/views/albums/index.html.erb new file mode 100644 index 0000000..550bbcb --- /dev/null +++ b/app/views/albums/index.html.erb @@ -0,0 +1,36 @@ + +
O Conteúdo da Variável Consulta Será Exibido Abaixo:
+ <%= form_tag("/artists", method: "get") do %> +