Complete Lesson 38 Part 2

main
Simon Quigley 1 year ago
parent 5a1ee09fd3
commit da9cec4d61

@ -7,6 +7,8 @@ class MoviesController < ApplicationController
def show
@movie = Movie.find(params[:id])
@fans = @movie.fans
@genres = @movie.genres.order(:name)
if current_user
@favorite = current_user.favorites.find_by(movie_id: @movie.id)
end
@ -43,6 +45,6 @@ class MoviesController < ApplicationController
private
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

@ -10,6 +10,10 @@
<%= f.label :rating %>
<%= 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.date_field :released_on %>

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

Loading…
Cancel
Save