Agile Web Development with Rails, Edition 4

26.2 HAML 25.2 rake

26.1 Active Merchant

Determine if a credit card is valid

edit Gemfile
gem 'activemerchant', '~> 1.21.0'
bundle install --local
Resolving dependencies...
Using rake (10.1.1)
Using multi_json (1.8.4)
Using activesupport (3.1.12) from source at /home/rubys/git/rails
Using builder (3.0.4)
Using i18n (0.6.9)
Using activemodel (3.1.12) from source at /home/rubys/git/rails
Using erubis (2.7.0)
Using rack (1.3.10)
Using rack-cache (1.2)
Using rack-mount (0.8.3)
Using rack-test (0.6.2)
Using hike (1.2.3)
Using tilt (1.3.7)
Using sprockets (2.0.4)
Using actionpack (3.1.12) from source at /home/rubys/git/rails
Using mime-types (1.25.1)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.4.4)
Using actionmailer (3.1.12) from source at /home/rubys/git/rails
Using active_utils (2.0.1)
Using json (1.8.1)
Using money (3.7.1)
Using activemerchant (1.21.0)
Using arel (2.2.3)
Using tzinfo (0.3.38)
Using activerecord (3.1.12) from source at /home/rubys/git/rails
Using activeresource (3.1.12) from source at /home/rubys/git/rails
Using bcrypt-ruby (3.0.1)
Using bundler (1.5.2)
Using highline (1.6.20)
Using net-ssh (2.8.0)
Using net-scp (1.1.2)
Using net-sftp (2.1.2)
Using net-ssh-gateway (1.2.0)
Using capistrano (2.15.5)
Using coffee-script-source (1.7.0)
Using execjs (2.0.2)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.3)
Using rdoc (3.12.2)
Using thor (0.14.6)
Using railties (3.1.12) from source at /home/rubys/git/rails
Using coffee-rails (3.1.1) from source at /home/rubys/git/coffee-rails
Using jquery-rails (3.1.0)
Using jquery-ui-rails (4.1.1)
Using mysql2 (0.3.15)
Using rails (3.1.12) from source at /home/rubys/git/rails
Using rvm-capistrano (1.5.1)
Using sass (3.2.14)
Using sass-rails (3.1.7) from source at /home/rubys/git/sass-rails
Using sqlite3 (1.3.8)
Using uglifier (2.4.0)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.
edit script/creditcard.rb
credit_card = ActiveMerchant::Billing::CreditCard.new(
  :number     => '4111111111111111',
  :month      => '8',
  :year       => '2009',
  :first_name => 'Tobias',
  :last_name  => 'Luetke',
  :verification_value  => '123' 
)
 
puts "Is #{credit_card.number} valid?  #{credit_card.valid?}"
rails runner script/creditcard.rb
[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.
Is 4111111111111111 valid?  false

26.2 HAML 25.2 rake