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 @@ + +
+

+
+
+

Albums List <%= @albums.count %>

+
+ <%= form_tag("/albums", method: "get") do %> +
+
+ +
+ <%= text_field_tag(:title, params['title'], class: "form-control") %> +
+ <%= submit_tag("Search", class: 'btn btn-outline-primary') %> +
+
+<% end %> + +
+ + +
+
\ No newline at end of file diff --git a/app/views/artists/index.html.erb b/app/views/artists/index.html.erb index 3d26cfd..b6f865d 100644 --- a/app/views/artists/index.html.erb +++ b/app/views/artists/index.html.erb @@ -1,5 +1,27 @@ -

Desenvolvimento Web 2

+
+

+
+
+

Artist List <%= @artists.count %>

+
-

O Conteúdo da Variável Consulta Será Exibido Abaixo:

+ <%= form_tag("/artists", method: "get") do %> +
+
+ +
+ <%= text_field_tag(:name, params['name'], class: "form-control") %> +
+ <%= submit_tag("Search", class: 'btn btn-outline-primary') %> +
+
+<% end %> -<%= @consulta.try(:inspect) %> +
+ +
+
\ No newline at end of file diff --git a/app/views/genres/index.html.erb b/app/views/genres/index.html.erb new file mode 100644 index 0000000..630ccb4 --- /dev/null +++ b/app/views/genres/index.html.erb @@ -0,0 +1,28 @@ +
+

+ +
+

Genres List <%= @genres.count %>

+
+ + +<%= form_tag("/genres", method: "get") do %> +
+
+ +
+ <%= text_field_tag(:name, params['name'], class: "form-control") %> +
+ <%= submit_tag("Search", class: 'btn btn-outline-primary') %> +
+
+<% end %> + +
+ +
+
\ No newline at end of file diff --git a/app/views/genres/new.html.erb b/app/views/genres/new.html.erb new file mode 100644 index 0000000..830171c --- /dev/null +++ b/app/views/genres/new.html.erb @@ -0,0 +1,6 @@ +

New Genre

+<%= @genre.errors.first %> +<%= form_for @genre do |f| %> + Nome: <%= f.text_field :name %> + <%= f.submit 'Save' %> +<% end %> diff --git a/app/views/genres/show.html.erb b/app/views/genres/show.html.erb new file mode 100644 index 0000000..3b58d00 --- /dev/null +++ b/app/views/genres/show.html.erb @@ -0,0 +1,8 @@ +

Showing Genre

+ +
+ ID: <%= @genre.id %>
+ Name: <%= @genre.name %>
+ Created at: <%= format(@genre.created_at) %>
+ Updated at: <%= format(@genre.updated_at) %>
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 49e0033..a986aaa 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -3,12 +3,62 @@ RailsWindows <%= csrf_meta_tags %> - + + + + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + + <%= yield %> diff --git a/app/views/tracks/index.html.erb b/app/views/tracks/index.html.erb new file mode 100644 index 0000000..48d227f --- /dev/null +++ b/app/views/tracks/index.html.erb @@ -0,0 +1,29 @@ + + +
+

+
+
+

Track List <%= @tracks.count %>

+
+ + <%= form_tag("/tracks", method: "get") do %> +
+
+ +
+ <%= text_field_tag(:name, params['name'], class: "form-control") %> +
+ <%= submit_tag("Search", class: 'btn btn-outline-primary') %> +
+
+<% end %> + +
+ +
+
diff --git a/config/routes.rb b/config/routes.rb index 6c4e4ee..260ef24 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do resources :artists + resources :genres, except: :destroy root 'artists#index' end