简体   繁体   中英

Rails 5 Unpermitted Parameter Upon Save

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!

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))

你必须发送tag_attributes PARAM代替tag -看你日志输出

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM