Can't mass-assign protected attributes attr_accessor and attr_accessible

半腔热情 提交于 2019-12-05 11:29:55

attr_accessor :person_id and attr_accessible :person_id are not the same.

attr_accessor is the Ruby method. In short its shortcut for methods:

def person_id
  @person_id
end

def person_id=(value)
  @person_id = value
end

attr_accessible is the Rails method. Which gets list of attributes allowed to be mass-assigned. You can read about here.

Thus in your case you need both of them.

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