diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-08 01:13:14 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-08 01:13:14 -0800 |
commit | bf34a360dd9ecaf4260b310f415cb93eddcb6b34 (patch) | |
tree | d5ff35d38d9af2f6cdb00fba800da4922c7f27aa /actionpack/lib | |
parent | 188b8c39da57abccb204d267f857646975680474 (diff) | |
parent | 677f968b771c837ae9bf4d9117372717e1bb6c11 (diff) | |
download | rails-bf34a360dd9ecaf4260b310f415cb93eddcb6b34.tar.gz rails-bf34a360dd9ecaf4260b310f415cb93eddcb6b34.tar.bz2 rails-bf34a360dd9ecaf4260b310f415cb93eddcb6b34.zip |
Merge pull request #3900 from jfturcot/accessible_wrap_params
ParamsWrapper only wrap the accessible attributes when they were set
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/params_wrapper.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb index 9dcea86253..5c28a8074f 100644 --- a/actionpack/lib/action_controller/metal/params_wrapper.rb +++ b/actionpack/lib/action_controller/metal/params_wrapper.rb @@ -43,6 +43,11 @@ module ActionController # wrap_parameters :person, :include => [:username, :password] # end # + # On ActiveRecord models with no +:include+ or +:exclude+ option set, + # if attr_accessible is set on that model, it will only wrap the accessible + # parameters, else it will only wrap the parameters returned by the class + # method attribute_names. + # # If you're going to pass the parameters to an +ActiveModel+ object (such as # +User.new(params[:user])+), you might consider passing the model class to # the method instead. The +ParamsWrapper+ will actually try to determine the @@ -162,7 +167,9 @@ module ActionController unless options[:include] || options[:exclude] model ||= _default_wrap_model - if model.respond_to?(:attribute_names) && model.attribute_names.present? + if model.respond_to?(:accessible_attributes) && model.accessible_attributes.present? + options[:include] = model.accessible_attributes.to_a + elsif model.respond_to?(:attribute_names) && model.attribute_names.present? options[:include] = model.attribute_names end end |