Skip to content

Instantly share code, notes, and snippets.

@steveh
Created August 22, 2011 20:32
Show Gist options
  • Save steveh/1163453 to your computer and use it in GitHub Desktop.
Save steveh/1163453 to your computer and use it in GitHub Desktop.
class ActiveDecorator
include ::Rails.application.routes.url_helpers
def default_url_options
::ActionMailer::Base.default_url_options
end
attr_reader :decorated
def initialize(decorated)
@decorated = decorated
end
end
module Api
class ThingDecorator < ActiveDecorator
def as_json(options = {})
thing = decorated
{
:id => thing.id,
:name => thing.name,
}
end
end
end
thing = Thing.find(1)
decorator = Api::ThingDecorator.new(thing)
render :json => decorator.as_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment