In Rails 8 the method expect has been introduced to mitigate some issues with the current params.require(:foo).permit(:bar) approach. One issue with the current approach is that if someone sends unexpected data, say POST { foo: "bam" } the Rails app will crash with a NoMethodError because the .permit method doesn't exist on String. The expect method handles this issue and will instead return a proper 400 error.
So, we should support this in upcoming versions of Pundit.
The expect method has a bit of a different syntax unfortunately so we can't just change it. I guess we either we have to make it required > some version, or configurable in Pundit. I haven't looked closely on how to best handle this yet.
Docs: https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect
In Rails 8 the method
expecthas been introduced to mitigate some issues with the currentparams.require(:foo).permit(:bar)approach. One issue with the current approach is that if someone sends unexpected data, sayPOST { foo: "bam" }the Rails app will crash with aNoMethodErrorbecause the.permitmethod doesn't exist onString. Theexpectmethod handles this issue and will instead return a proper 400 error.So, we should support this in upcoming versions of Pundit.
The
expectmethod has a bit of a different syntax unfortunately so we can't just change it. I guess we either we have to make it required > some version, or configurable in Pundit. I haven't looked closely on how to best handle this yet.Docs: https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect