Complete Lesson 38 Part 2

main
Simon Quigley 1 year ago
parent 5a1ee09fd3
commit da9cec4d61

@ -7,6 +7,8 @@ class MoviesController < ApplicationController
def show def show
@movie = Movie.find(params[:id]) @movie = Movie.find(params[:id])
@fans = @movie.fans @fans = @movie.fans
@genres = @movie.genres.order(:name)
if current_user if current_user
@favorite = current_user.favorites.find_by(movie_id: @movie.id) @favorite = current_user.favorites.find_by(movie_id: @movie.id)
end end
@ -43,6 +45,6 @@ class MoviesController < ApplicationController
private private
def movie_params def movie_params
params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross, :director, :duration, :image_file_name) params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross, :director, :duration, :image_file_name, genre_ids: [])
end end
end end

@ -10,6 +10,10 @@
<%= f.label :rating %> <%= f.label :rating %>
<%= f.select :rating, Movie::RATINGS, prompt: "Pick one" %> <%= f.select :rating, Movie::RATINGS, prompt: "Pick one" %>
<div class="checkboxes">
<%= f.collection_check_boxes(:genre_ids, Genre.order(:name), :id, :name) %>
</div>
<%= f.label :released_on %> <%= f.label :released_on %>
<%= f.date_field :released_on %> <%= f.date_field :released_on %>

@ -55,5 +55,13 @@
<% end %> <% end %>
</ul> </ul>
<% end %> <% end %>
<% if @genres.present? %>
<h4>Genres</h4>
<ul>
<% @genres.each do |g| %>
<li><%= g.name %></li>
<% end %>
</ul>
<% end %>
</aside> </aside>
</section> </section>

Loading…
Cancel
Save