Many-to-Many Nested Attributes in Rails 4 (with strong parameters)

泄露秘密 提交于 2019-12-03 20:09:11

You should pass also 'id' in each of your nested model params try :

def referral_params
    params.require(:referral).permit(prospects_attributes: [:id,:first_name, :last_name, :email], alumnis_attributes: [:id,:first_name, :last_name, :email], schools_attributes: [:id,:name])    
end

Have swing

Cheers

You parameters are not being past to the controller as strong parameters is expecting.

From you server log:

"referral" => {
  "school"  => { 
     "name" => "asdf" }, 
  "alumnis" => { 
    "first_name" => "asdf", 
    "last_name"  => "asfd", 
    "email"      => "asdf" 
  }, 
  "prospects" => {
    "first_name" => "asdf", 
    "last_name"  => "asdf", 
    "email"      => "asdf" 
  }
 }

Strong parameters is expecting prospects_attributes, alumnis_attributes and schools_attributes so prospects, alumnis and school are getting blocked and the objects are getting created without any attributes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!