Skip to content

Instantly share code, notes, and snippets.

@kuon
Created April 28, 2011 10:12
Show Gist options
  • Save kuon/946123 to your computer and use it in GitHub Desktop.
Save kuon/946123 to your computer and use it in GitHub Desktop.
json variants
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