Skip to content

Instantly share code, notes, and snippets.

@brett-richardson
Forked from alexslade/rails_responder.rb
Created June 19, 2014 19:00
Show Gist options
  • Save brett-richardson/e737d5b2b5249839ee28 to your computer and use it in GitHub Desktop.
Save brett-richardson/e737d5b2b5249839ee28 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment