Reputation: 2693
I'm working with two models Submission
and Tag
. Submission
has_one :tag
. In my controller I have set up my submission_params
as follows:
params.require(:submission).permit(:domain, tag_attributes:[:tag_text, :notes])
However, I'm getting the error: Unpermitted parameter: tag
From my log:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"BEJZXOERC3cGSZFlAL91kRJgR+YFcHd6+yMYilDyu/NyN1YviwahKwrifAQfWMdu53/NYCnOVD4NHNXSZmPk7Q==", "submission"=>{"domain"=>"test", "tag"=>{"tag_text"=>"test tag", "notes"=>"test"}}, "commit"=>"Submit"}
Perhaps I'm just rusty and am overlooking something or does rails5 have a new trick to dealing with strong params? Thanks in advance!
Upvotes: 0
Views: 1211
Reputation: 52347
If this is
accepts_nested_attributes :tag
here is how you'd permit it:
# :_destroy is for being able to delete the nested tag
params
.require(:submission)
.permit(:domain, tag_attributes: %i(id submission_id tag_text notes _destroy))
Upvotes: 1
Reputation: 754
You have to send tag_attributes
param instead of tag
- see you log output
Upvotes: 0