Rails 4 Strong parameters : permit all attributes?

后端 未结 4 2024
日久生厌
日久生厌 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条回答
  •  旧时难觅i
    2020-12-07 18:56

    You can call the bang version of permit.

    params.require(:user).permit!
    

    Strong Params README on Github

    Source code for reference:

    def permit!
      each_pair do |key, value|
        convert_hashes_to_parameters(key, value)
        self[key].permit! if self[key].respond_to? :permit!
      end
    
      @permitted = true
      self
    end
    

提交回复
热议问题