如何在rails 4中使用PayPal结帐

时间:2014-11-07 15:00:30

标签: paypal ruby-on-rails-4.1

我正在尝试将PayPal电子广告添加到我的RoR应用程序中。所以我按照以下步骤进行: 我的panier.rb:

class Panier < ActiveRecord::Base
  belongs_to :user



 def paypal_url(return_path)
values = {
    :business => 'r.karoui-buyer@loganddrive.com',
    :cmd => '_cart',
    :upload => 1,
    :return => return_path,
    :invoice => id
}
line_items.each_with_index do |item, index|
  values.merge!({
                    "amount_#{index+1}" => item.price,
                    "item_name_#{index+1}" => item.book.title,
                    "item_number_#{index+1}" => item.id,
                    "quantity_#{index+1}" => 1
                })
  end

 "#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
end
end

我的details.html.erb:我在哪里拨打PayPal服务

<%= @panier.book_id %> | <%= @panier.price %> | <%= link_to 'acheter' , @panier.paypal_url(paniers_path) %>

但是我收到了这个错误:

  

未定义的局部变量或#

的方法`line_items'

我只关注此railsCast教程:

  

http://railscasts.com/episodes/141-paypal-basics

我应该代替line_items.each_with_index do | item,index |如果它在这里错误,如果没有请帮助我找出问题在哪里

1 个答案:

答案 0 :(得分:0)

尝试

def paypal_url(return_path)
values = {
    :business => 'r.karoui-buyer@loganddrive.com',
    :cmd => '_cart',
    :upload => 1,
    :return => return_path,
    :invoice => id
}

 values.merge!({
                "amount_#{index+1}" => item.price,
                "item_name_#{index+1}" => item.book.title,
                "item_number_#{index+1}" => item.id,
                "quantity_#{index+1}" => 1
            })


 "#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?" + values.to_query
end