| 648 | | # If this macro is used, only those attributes named in it will be accessible for mass-assignment, such as |
|---|
| 649 | | # <tt>new(attributes)</tt> and <tt>attributes=(attributes)</tt>. This is the more conservative choice for mass-assignment |
|---|
| 650 | | # protection. |
|---|
| 651 | | # |
|---|
| 652 | | # Example: |
|---|
| | 648 | # Similar to the attr_protected macro, this protects attributes of your model from mass-assignment, |
|---|
| | 649 | # such as <tt>new(attributes)</tt> and <tt>attributes=(attributes)</tt> |
|---|
| | 650 | # however, it does it in the opposite way. This locks all attributes and only allows access to the |
|---|
| | 651 | # attributes specified. Assignment to attributes not in this list will be ignored and need to be set |
|---|
| | 652 | # using the direct writer methods instead. This is meant to protect sensitive attributes from being |
|---|
| | 653 | # overwritten by URL/form hackers. If you'd rather start from an all-open default and restrict |
|---|
| | 654 | # attributes as needed, have a look at attr_protected. |
|---|
| | 655 | # |
|---|
| | 656 | # ==== Options |
|---|
| | 657 | # |
|---|
| | 658 | # <tt>*attributes</tt> A comma separated list of symbols that represent columns _not_ to be protected |
|---|
| | 659 | # |
|---|
| | 660 | # ==== Examples |
|---|
| 658 | | # Passing an empty argument list protects all attributes: |
|---|
| 659 | | # |
|---|
| 660 | | # class Product < ActiveRecord::Base |
|---|
| 661 | | # attr_accessible # none |
|---|
| 662 | | # end |
|---|
| 663 | | # |
|---|
| 664 | | # If you'd rather start from an all-open default and restrict attributes as needed, have a look at |
|---|
| 665 | | # attr_protected. |
|---|
| | 666 | # customer = Customer.new(:name => "David", :nickname => "Dave", :credit_rating => "Excellent") |
|---|
| | 667 | # customer.credit_rating # => nil |
|---|
| | 668 | # customer.attributes = { :name => "Jolly fellow", :credit_rating => "Superb" } |
|---|
| | 669 | # customer.credit_rating # => nil |
|---|
| | 670 | # |
|---|
| | 671 | # customer.credit_rating = "Average" |
|---|
| | 672 | # customer.credit_rating # => "Average" |
|---|