Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 437957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:37:49+00:00 2026-05-12T20:37:49+00:00

I was going through Ryan Bates’ video on Active Merchant integration video Railscast #145

  • 0

I was going through Ryan Bates’ video on Active Merchant integration video Railscast #145 and my question was regarding the creation of the @credit_card method that he defines within the Order.rb method.

def credit_card
  @credit_card||=ActiveMerchant::Billing::CreditCard.new(
    :type=>card_type,
    :number=>card_number,
    :verification_value=>card_verification,
    :month=>card_expires_on.month,
    :year=>card_expires_on.year,
    :first_name=>first_name,
    :last_name=>last_name
  )

end

What I don’t follow is how does this method get called. The form_for in the new method creates an @order object while and there is no mention of the credit_card method. How does the credit_card method get called to initiate the creation of the @credit_card object.

I am aware of virtual attributes but I dont know how the credit_card method is actually called.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:37:49+00:00Added an answer on May 12, 2026 at 8:37 pm

    Looking at the screencast code here.

    In app/views/orders/new.html.erb

    We can see the order form, and from the first line

    <% form_for @order do |f| %>
    

    We see that, on submission, the form use the oders_controller create method.

    In app/controller/orders_controller.rb

        def create
          @order = current_cart.build_order(params[:order])
          @order.ip_address = request.remote_ip
    
          if @order.save
            if @order.purchase
              render :action => "success"
            else
              render :action => "failure"
            end
          else
            render :action => 'new'
          end
        end
    

    We can see that @order is Order instance built from the cart. Nothing special here
    This order is now saved with @order.save and then the purchase method is called on @order

    Let’s take a look at this purchase method!

    in app/model/order.rb

        def purchase
          response = GATEWAY.purchase(price_in_cents, credit_card, purchase_options)
          transactions.create!(:action => "purchase", :amount => price_in_cents, :response => response)
          cart.update_attribute(:purchased_at, Time.now) if response.success?
          response.success?
        end
    

    Second line response = GATEWAY.purchase(price_in_cents, credit_card, purchase_options)
    . The credit_card method is called there as an argument of GATEWAY.purchase

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going through the railscast no 73 ( http://railscasts.com/episodes/73-complex-forms-part-1 ), where Ryan Bates explains
After going through the discussion here I have one more question now. Lets assume,
Going through the Active Support Core Extensions guide , it looks like some of
while going through video tutorials for mvc2 which i downloaded from microsoft's website, the
Going through some of my older Delphi projects and upgrading them to D2009, as
Going through Javascript documentation, I found the following two functions on a Javascript object
Going through the microsoft authentication tutorial listed here they have you create a master
Going through some documentation on modifying CGImageRef data, I came across a strange example
While going through many resources on multithreaded programming, reference to volatile specifier usually comes
Just going through the sample Scala code on Scala website, but encountered an annoying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.