Created
April 28, 2011 10:12
-
-
Save kuon/946123 to your computer and use it in GitHub Desktop.
json variants
This file contains 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 Ambience < ActiveRecord::Base | |
attr_accessible :name | |
short_serialize_options :only => [:id, :name] | |
long_serialize_options :except => :deleted | |
def serializable_hash(options = nil) | |
options ||= {} | |
variant = options[:variant] | |
options.delete :variant | |
if not variant | |
super(options) | |
elsif variant == :short | |
super(short_serialize_options) | |
elsif variant == :long | |
super(long_serialize_options) | |
end | |
end | |
end | |
# to be used like | |
render :json => @ambiences.to_json(:variant => :short) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment