-
-
Save dnch/1350453 to your computer and use it in GitHub Desktop.
Calculating Mass-Assignable ActiveRecord Attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Article < ActiveRecord::Base | |
# Has attributes: :title, :body, :active | |
attr_protected :active | |
end | |
class Image < ActiveRecord::Base | |
# Has attributes: :title, :filename, :active | |
attr_accessible :title | |
end | |
a = Article.new | |
a.attributes # => [:title, :body, :active] | |
Article.protected_attributes # => [:active] | |
Article.accessible_attributes # => [] # Where are :title and :body? | |
p = Photo.new | |
p.attributes # => [:title, :filename, :active] | |
Photo.protected_attributes # => [] # Where are :filename and :active? | |
Photo.accessible_attributes # => [:title] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment