Last active
August 29, 2015 14:02
-
-
Save alexslade/f24278d9c584f4d9e3bc to your computer and use it in GitHub Desktop.
This file contains 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
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 |
This file contains 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
def create | |
card = current_user.credit_cards.create(card_params) | |
if card.persisted? | |
render :success | |
else | |
render :failure | |
end | |
end |
This file contains 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
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 |
This file contains 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
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
the responder example could be simplified: