Rails 4 Strong parameters : permit all attributes?

后端 未结 4 2002
日久生厌
日久生厌 2020-12-07 18:37

I\'m building a web app with Rails 4 strong parameters.

When building the admin back office controllers, I wonder what is the best way to permit all the model attrib

4条回答
  •  醉梦人生
    2020-12-07 19:07

    Skull0inc's answer works, but you might want to remove created_at and updated_at. The intention of strong params is to list only the attributes you want updatable by the controller. Something like...

    def user_params
      params.require(:user).permit(User.column_names - ["created_at", "updated_at"])
    end
    

提交回复
热议问题