i have two tables in Ruby on Rails, Movies and Directors. Movies has belongs_to association to director, and director has has_many association to movies. I can create both just fine, but when i try to edit a movie to include its director via a dropdown(using form.collection_select) and click update i get this message:
1 error prohibited this movie from being saved:
Director must exist
This is the code for the dropdown (its labeled in my native language, sorry about that)
"
<%= form.label :director_id, "Režisér", style: "display: block" %>
<%= form.collection_select(:director_id, Director.all, :id, :first_name, {:prompt => 'Vyberte režiséra'}, :selected => @movie.director_id ) %>
"
I'm a newbie to Ruby on Rails and my search on this issue has so far been unsuccessful and i have no idea how to ask Mr Google correctly
CodePudding user response:
solved thanks to max's comment below, i simply needed to add the director_id reference parameter to my movies_controller.rb like so:
def movie_params
params.require(:movie).permit(:name, :release_date, :description, :director_id)
end