Created
December 30, 2010 21:34
-
-
Save dougalcorn/760333 to your computer and use it in GitHub Desktop.
some template code using ActiveModel::MassAssignmentSecurity to initialize with hash
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 Person | |
include ActiveModel::MassAssignmentSecurity | |
attr_accessor :name, :birthday, :handsomeness | |
attr_protected :handsomeness | |
def initialize(params = {}) | |
self.attributes = params | |
end | |
def attributes=(params = {}) | |
sanitize_for_mass_assignment(params).each do |k, v| | |
send("#{k}=", v) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment