Skip to content

Instantly share code, notes, and snippets.

<%= select(:post, :category, Post::CATEGORIES, :disabled => 'private') %>
<!— Give's you something like —>
<select name="post[category]">
<option>story</option>
<option>joke</option>
<option>poem</option>
<option disabled="disabled">private</option>
</select>
<%= options_from_collection_for_select(@product.sizes, :name, :id, :disabled => lambda{|size| size.out_of_stock?}) %>
<!-- If small and medium returned true for the method out_of_stock?, you’d get something like: -->
<option value=“23“ disabled=“disabled“>small</option>
<option value=“24“ disabled=“disabled“>medium</option>
<option value=“25“>large</option>
<option value=“26“>extra large</option>
<%= options_for_select(
['Choose a size', 'small', 'medium', 'large'],
nil, # selected value
'medium' # disabled value
) %>
<!-- Gives you -->
<option value="Choose a size">Please choose a size</option>
<option value="s">small</option>
<%= options_from_collection_for_select(
@products,
:id,
:name,
nil, # selected value(s)
lambda{|p| !p.in_stock? } # disabled value(s) identified with a proc
) %>
git fetch origin other_branch:other_branch
* [new branch] other_branch -> other_branch
git branch
* master
other_branch
git checkout other_branch
# Or, in one swift command:
git checkout -t origin/other_branch
gateway = ActiveMerchant::Billing::ProtxGateway.new({
:login => 'test',
:password => 'password',
:enable_3d_secure => true
})
response = gateway.purchase(100, credit_card)
if response.success?
puts "Purchase successfully made"
else
puts "Purchase not authorised, try again"
end
response = gateway.purchase(100, credit_card)
if response.success?
puts "Purchase successfully made"
elsif response.three_d_secure?
puts "Purchase requires additional 3D Authentication"
else
puts "Purchase not authorised, try again"
end
response = gateway.three_d_complete(pa_res, md)
if response.success?
puts "Authentication complete and purchase successfully made"
else
puts "Purchase not authorised or authentication failed, try again"
end
def create
@credit_card = ActiveMerchant::Billing::CreditCard.new(params[:credit_card])
@billing_address = Address.new(params[:address])
@payment = @order.payments.create(:credit_card => @credit_card, :address => @billing_address)
if @payment.success?
redirect_to complete_order_url(@order)
elsif @payment.requires_authentication?
# A view with an iframe from which the user is redirected to the authentication page
render :action => 'three_d_iframe'
else