Skip to content

Instantly share code, notes, and snippets.

@adammcarth
Created April 22, 2014 08:14
Show Gist options
  • Save adammcarth/11169736 to your computer and use it in GitHub Desktop.
Save adammcarth/11169736 to your computer and use it in GitHub Desktop.
# 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
# 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
<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