Rails mass assignment definition and attr_accessible use

≡放荡痞女 提交于 2019-11-30 17:18:49

All of your assumptions are correct. Without attr_accessible, all fields are open to mass assignment. If you start using attr_accessible, only the fields you specify are open to mass assignment.

As pointed out by Srdjan all of your assumptions are correct. Just so you know, there is also an attr_protected method which is the opposite of attr_accessible.

In other words

attr_protected :admin

will prevent :admin from being mass-assigned but will allow all other fields.

Srdjan's answer is correct assuming that config.active_record.whitelist_attributes is set to false in your config/application.rb.

If it is set to true, all attributes will be protected from mass assignment by default unless attr_accessible or attr_protected is used.

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