This repository was archived by the owner on Aug 17, 2017. It is now read-only.
Revisiting problems with multi-parameter attributes #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been looking at multi-parameter attributes quite a bit over the last week: I have a Rails app which isn't using an ActiveRecord instance to process the params, but is using the model-ish objects with the form helpers, producing date_select output of the "object[date(1i)]" form.
Looking over the activity around this stuff in ActiveRecord and more widely in Rails it looks like
strong_parameters
is a good place to start. I've seen the recent activity here (#17 and #21) and Carlos' refactorings happening in e.g. rails/rails@ec31680I've been wondering about an approach which separates out the multiparameter parsing code from
ActiveRecord::AttributeAssignment
and, eventually, pushes the stitching-together of multiparameter attributes into ActionDispatch, that doesn't do anything with higher-level (model) datatypes, but does know about:This should allow the multi-parameter code to select for mult-parameter-ness based on whether the value is an Array or not, much as with nested attrs now:
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_assignment.rb#L97-104
(I realise
nested_attributes_for
might require a bit more thought, but it doesn't feel too big to me.)If this was in the param processing chain before the controller method then the failing test in this pull request would cease being be a failing test. It'd be good to have the complexity for multi-parameter attrs in one place. Putting it in
ActionDispatch
seems like, if nothing else, a win for code DRYness:strong_parameters
will need to know about this stuff otherwise...Obviously, actually implementing this will require changes in ActiveRecord and ActionPack. If there are no objections, I'll ping Carlos and talk to him about how and where to safely extract this functionality (I have a good idea, I just don't want to tread on the work being done there already), and also start reaching out to people working on
ActionDispatch
.