Created
April 22, 2014 08:14
-
-
Save adammcarth/11169736 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
# Option 2: Save true or false into the database | |
# This is the model file | |
before_save :verify_use_card | |
def verify_use_card | |
if self.use_credit_card == 1 | |
self.use_credit_card = true | |
else | |
self.use_credit_card = false | |
end | |
end | |
# Implementation in a controller: | |
@client = Client.find(params[:id]) | |
if @client.use_credit_card | |
process_card(@client.card_number) | |
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
# Option 1: Have 0 or 1 saved into the database field. | |
def use_credit_card?(client_id) | |
@client = Client.find(client_id) | |
if @client.use_credit_card == 1 | |
return true | |
else | |
return false | |
end | |
end | |
# Implementation: | |
@client = Client.find(params[:id]) | |
if use_credit_card?(@client.id) | |
process_card(@client.card_number) | |
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
<input type="checkbox" id="targetMe"> | |
<input type="text" id="client_use_credit_card" name="client[use_credit_card]" value="0" style="display:none;"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment