Since strong parameters came out I was struggling with the thought that I need to keep an extra method around in the controller for parameter whitelisting. It was absolutely right to move the responsibility to whitelist end user submissions from the ActiveModel to ActionController - but the extra method in the controller was bothering me still.
This gem looks great to me. I think it could very well reduce code duplication (and make those strong parameter definitions look a little cleaner).
One thing I think about a lot is how a Rails 4 app could be built with many, many controllers that share the definition of the strong parameters across controllers (or don’t share them, as the case need be) — without repeating code, of course. I could brainstorm different ways (inherited controller classes, with the strong parameters defined in base classes, using modules to mix-in the strong parameters, etc)
In general I find this syntax (yours) to be very clean, very terse, and easy to read.
Looks interesting, but more often than not I use the same parameter whitelisting across all actions in a controller. This means I’ll define a private method like user_params in the controller, and use it in every action.
In terms of param whitelisting reuse, for the case where several controllers can create the same type of model, I just add private methods to ApplicationController.
Anyway, after getting feedback (both negative and positive) i thought this one over.
The extra method bothers me because it seems to be a piece of code in a defined structure that changes only by context. In my opinion, just like many other rails macros / solutions - code repetitions should be contained and narrowed down, in here it’s not the case.
I redesigned the gem to have an even easier DSL imo. now you can simply use params. I am not sure that the way that I chose here (reconstructing the params hash and filtering it in runtime is a good idea, but i think that’s a start. and hi, you can keep on using “params” and not some funky “user_params” or “create_params”.