All threads / ActionController::Parameters.new.require(:person)

Ask A Question

Notifications

You’re not receiving notifications from this thread.

ActionController::Parameters.new.require(:person)

Penguin asked in Rails

Hello,

Note:I configured the App with config.action_controller.action_on_unpermitted_parameters = :raise.

Assuming I have a Model Person with attributes :name, :age.

If params = { name: "penguin", age: "99", style: "emperor" }

params.require(:person).permit(:name, :age) will not raise anything because params.require(:person) actually disregard the style: attribute without raising anything and returns { name: "penguin", age: "99" }

Now if I do params.permit(:id, :name, :age, :person => {}), it does raise "found unpermitted parameters: :style".

Is there a way to make .require not filtering the params without raising anything?

Thanks

I ended up also disabling wrap_parameters: wrap_parameters format: []
So now I can simply do params.permit(:id, :name, :age).

Not sure if there is a better way.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 38,558+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.