Currently strong_parameters do not allow you to overload keys in permitted 
parameters.  I am proposing a change that allows you to accept scalar 
values, arrays, or a hash of parameters for a particular permitted key, 
instead of exclusively one of the three.  

This is allowed by passing an array with multiple of the same key with 
different values.  For example: `user: [:name, {:name => []}, {:name => 
[:first, :middle]}]`.  

The particular case that this addresses for me is that I have a polymorphic 
object whose attributes can either be a scalar value or another rails 
model.  This solution allows me to provide one permitted parameters hash to 
accept all possible types of the polymorphic object without having to 
condition on the parameters themselves.  

You can take a look at the code I have written to solve this problem here:  
https://github.com/pblesi/rails/commit/1ce634e9990b9b5397b7e5e6aa265ed0410379fc

I appreciate any feedback on the proposed solution.  

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to