I have a form:
= simple_form_for @character do |f|
= f.input :name
= f.input :description
= f.simple_fields_for @movie_characters do |fmc|
= fmc.association :movie, value_method: :id, label_method: :title
= f.submit
Relationship here is Character has many MovieCharacters and MovieCharacter belongs_to Movie.
params I get from this form look like this:
{"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"6d8n1Z5AC3nF/cqzTInnMr5TyRhZFcGV8ssf5CsNkjskiD9lUL10nVDYeV4i0yS85Q87yNcIi+coFFDf0mpZ4w==", "character"=>{"name"=>"Joker", "description"=>"best villain ever", "movie_character"=>{"movie_id"=>"1"}}, "commit"=>"Update Character", "controller"=>"characters", "action"=>"update", "id"=>"1"}
character_params method looks like this:
def character_params
params.require(:character).permit(:name, :description, movie_characters_attributes: [:movie_id, :character_id])
end
Unfortunately while calling this method in controller I get "Unpermitted parameter: movie_character" warning. I also tried
def character_params
params.require(:character).permit(:name, :description, movie_characters: [:movie_id, :character_id])
end
But effects are the same. Can you tell me why it doesnt work?
UPDATE:
class Character < ActiveRecord::Base
has_many :movie_characters
accepts_nested_attributes_for :movie_characters
end
class MovieCharacter < ActiveRecord::Base
belongs_to :character
belongs_to :movie
end