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

Reply

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.

Reply
Join the discussion
Create an account Log in

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

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

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