Skip to content

Instantly share code, notes, and snippets.

@alexslade
Last active August 29, 2015 14:02
Show Gist options
  • Save alexslade/f24278d9c584f4d9e3bc to your computer and use it in GitHub Desktop.
Save alexslade/f24278d9c584f4d9e3bc to your computer and use it in GitHub Desktop.
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

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