Add regex support for permitting params#21
Conversation
|
👍 |
ec7b957 made strong_parameters 1.8 compatible
|
Added 929332d to revert to 1.8 hash syntax after the merging of pull request #19 |
|
I'd rather we just default to permit :published_at will also just automatically allow :published_at(x) -- instead of all this extra configuration. If you want to take a stab at a pull request that does that, please open a new ticket. I posted the same message to pull request #17. |
|
Though this does solve the ActionView DateHelper problem, we use the regex syntax for conveniences beyond just that. |
|
@dhh My 2¢. While I can be convinced that the We have project edit pages that provide a one stop shop for managing budgets, rates and project manager status on all the users assigned to the project. Every single one of these input fields is going to come through the params hash. As a point of reference, here is how you'd look each one up: params[:user-assignment-1234][:budget]
params[:user-assignment-1234][:hourly_rate]
params[:user-assignment-1234][:is_project_manager]
params[:user-assignment-4567][:budget]
params[:user-assignment-4567][:hourly_rate]
params[:user-assignment-4567][:is_project_manager]
# etcBeing able to do a strong params declaration like the following turns out to greatly reduce the amount of configuration, as it were, that we are doing in our controllers: params.permit(/^user-assignment-\d+$/ => [:budget, :hourly_rate, :is_project_manager])This is why we chose the regex route, rather than trying to code up each possible use case ( |
Instead of explicitly enumerating all permitted params as symbols, allow for regexes:
This also helps when using ActionView DateHelper methods. Instead of:
you can more tersely use something like:
(See pull request #17 for an alternate but less flexible solution to the DateHelper problem.)