Skip to content

Instantly share code, notes, and snippets.

@dougalcorn
Created December 30, 2010 21:34
Show Gist options
  • Save dougalcorn/760333 to your computer and use it in GitHub Desktop.
Save dougalcorn/760333 to your computer and use it in GitHub Desktop.
some template code using ActiveModel::MassAssignmentSecurity to initialize with hash
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