Skip to content

Commit

Permalink
Improve docs for attr_accessible|protected related to Hash#except|slice
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva authored and vijaydev committed Mar 8, 2012
1 parent 9bcd662 commit e63f04c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions activemodel/lib/active_model/mass_assignment_security.rb
Expand Up @@ -83,7 +83,7 @@ module ClassMethods
# end
# end
#
# When using the :default role :
# When using the :default role:
#
# customer = Customer.new
# customer.assign_attributes({ "name" => "David", "credit_rating" => "Excellent", :last_login => 1.day.ago }, :as => :default)
Expand All @@ -94,7 +94,7 @@ module ClassMethods
# customer.credit_rating = "Average"
# customer.credit_rating # => "Average"
#
# And using the :admin role :
# And using the :admin role:
#
# customer = Customer.new
# customer.assign_attributes({ "name" => "David", "credit_rating" => "Excellent", :last_login => 1.day.ago }, :as => :admin)
Expand All @@ -105,8 +105,9 @@ module ClassMethods
# To start from an all-closed default and enable attributes as needed,
# have a look at +attr_accessible+.
#
# Note that using <tt>Hash#except</tt> or <tt>Hash#slice</tt> in place of +attr_protected+
# to sanitize attributes won't provide sufficient protection.
# Note that using <tt>Hash#except</tt> or <tt>Hash#slice</tt> in place of
# +attr_protected+ to sanitize attributes provides basically the same
# functionality, but it makes a bit tricky to deal with nested attributes.
def attr_protected(*args)
options = args.extract_options!
role = options[:as] || :default
Expand Down Expand Up @@ -150,7 +151,7 @@ def attr_protected(*args)
# end
# end
#
# When using the :default role :
# When using the :default role:
#
# customer = Customer.new
# customer.assign_attributes({ "name" => "David", "credit_rating" => "Excellent", :last_login => 1.day.ago }, :as => :default)
Expand All @@ -160,15 +161,16 @@ def attr_protected(*args)
# customer.credit_rating = "Average"
# customer.credit_rating # => "Average"
#
# And using the :admin role :
# And using the :admin role:
#
# customer = Customer.new
# customer.assign_attributes({ "name" => "David", "credit_rating" => "Excellent", :last_login => 1.day.ago }, :as => :admin)
# customer.name # => "David"
# customer.credit_rating # => "Excellent"
#
# Note that using <tt>Hash#except</tt> or <tt>Hash#slice</tt> in place of +attr_accessible+
# to sanitize attributes won't provide sufficient protection.
# Note that using <tt>Hash#except</tt> or <tt>Hash#slice</tt> in place of
# +attr_accessible+ to sanitize attributes provides basically the same
# functionality, but it makes a bit tricky to deal with nested attributes.
def attr_accessible(*args)
options = args.extract_options!
role = options[:as] || :default
Expand Down

0 comments on commit e63f04c

Please sign in to comment.