Skip to content

Instantly share code, notes, and snippets.

@brett-richardson
Forked from ejlangev/gist:9b3f4d779d6512221c95
Last active August 29, 2015 14:02
Show Gist options
  • Save brett-richardson/9291ba2d526da26d35cd to your computer and use it in GitHub Desktop.
Save brett-richardson/9291ba2d526da26d35cd to your computer and use it in GitHub Desktop.
class CreditCardController < ApplicationController
def create
respond_with CreditCardCreator.new(params)
end
end
class Grouper::Responder
delegate :errors, to: :resource
def resource
raise NotImplementedError
end
def to_json
call
resource
end
end
class CreditCardCreator < Grouper::Responder
def initialize(params)
@params = params
end
def resource
@resource ||= CreditCard.new(@params)
end
def call
resource.save
...
response = Stripe.create_card(resource)
unless response.success?
errors << response.error_message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment