why am I getting a ForbiddenAttributesError when using protected_attributes gem

倖福魔咒の 提交于 2019-12-13 02:30:32

问题


We just upgraded to rails 4.1.13 from 4.0.1. We've dragged our feet at implementing strong parameters. As such, we are still using the protected_attributes gem so we can use the old behavior.

Now, we are getting an ActiveModel::ForbiddenAttributesError. I do not understand why, since we are using the protected_attributes gem..


回答1:


You can basically use the following code snippet to mark attributes safe for mass assignment other than the id attribute of your model

attr_protected :id

Please note that doing so makes all the attributes other than id of your model safe for mass assignment. If most of the attributes of your model can be mass assigned, I think using attr_protected instead of using attr_accessible makes more sense as it does the same job without writing more lines of code.



来源:https://stackoverflow.com/questions/33599112/why-am-i-getting-a-forbiddenattributeserror-when-using-protected-attributes-gem

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