Skip to content

Instantly share code, notes, and snippets.

@xrl
Created April 16, 2014 20:52
Show Gist options
  • Save xrl/10931891 to your computer and use it in GitHub Desktop.
Save xrl/10931891 to your computer and use it in GitHub Desktop.
class AdsSerializer < ActiveModel::Serializer
attributes :target_url,
:image_url,
:thumb_url
def image_url
image.url
end
def thumb_url
thumb.url
end
end
class AndroidAdSerializer < AdsSerializer
attributes :something_custom
end
# in the controller
if @i_know_its_android
render json: @ad, serializer: AndroidAdSerializer
else
render json: @ad
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment