Created
August 22, 2011 20:32
-
-
Save steveh/1163453 to your computer and use it in GitHub Desktop.
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 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 |
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
module Api | |
class ThingDecorator < ActiveDecorator | |
def as_json(options = {}) | |
thing = decorated | |
{ | |
:id => thing.id, | |
:name => thing.name, | |
} | |
end | |
end | |
end |
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
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