Skip to content

Instantly share code, notes, and snippets.

@bkono
Created July 2, 2012 07:10
Show Gist options
  • Save bkono/3031626 to your computer and use it in GitHub Desktop.
Save bkono/3031626 to your computer and use it in GitHub Desktop.
Sample ActiveModel based class supporting from_json
class Person
include ActiveModel::Serialization
include ActiveModel::Serializers::JSON
attr_accessor :name, :email
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def attributes
{
:name => @name,
:email => @email
}
end
def attributes=(params)
params.each do |k,v|
puts "#{k} : #{v}"
send("#{k}=", v) if attributes.has_key? k.to_sym
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment