Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def create
card_saver = Billing::SaveCreditCard.new(user: current_user, card: card_params)
responder = respond do |r|
r.success { render :success }
r.failure { render :failure }
end
card_saver.call(responder)
end
def create
card = current_user.credit_cards.create(card_params)
if card.persisted?
render :success
else
render :failure
end
end
def create
card_saver = Billing::SaveCreditCard.new(user: current_user, card: card_params)
responder = SaveCardHandler.new(self)
card_saver.call(responder)
end
class SaveCardHandler < SimpleDelegator
def success
render :success
end
def failure
render :failure
end
end
def create
card = Billing::SaveCreditCard.new(user: current_user, card: card_params).call
if card.persisted?
render :success
else
render :failure
end
end
@mikekelly
Copy link

mikekelly commented Jun 18, 2014

the responder example could be simplified:

def create
  SaveCard.call(
    listener: SaveCardHandler.new(self),
    user: current_user,
    card: card_params
  )
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment