Created
July 2, 2012 07:10
-
-
Save bkono/3031626 to your computer and use it in GitHub Desktop.
Sample ActiveModel based class supporting from_json
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::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