【问题标题】:PayPal integration in Ruby on RailsRuby on Rails 中的 PayPal 集成
【发布时间】:2015-05-26 05:44:24
【问题描述】:

我想将 PayPal 支付系统添加到我的 RoR 应用。为此,我确实安装了paypal-sdk-rest gem。

我有一个模型 Feed 和 index.html.rb 内部,路径是:

get '/:locale/feed', to: 'feed#index', as: 'feed'

我要粘贴下一段代码:

<%= link_to 'checkout', feed.paypal_url(products_url) %> 

在模型 feed.rb 内部:

def paypal_url(return_url) 
values = { 
    :business => 'my_paypal_mail@gmail.com',
        :cmd => '_cart',
    :upload => 1,
    :return => return_url,
}   
values.merge!({ 
    "amount_1" => unit_price,
    "item_name_1" => name,
    "item_number_1" => id,
    "quantity_1" => '1'
})

     "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query
 end 

但它打印出我:

undefined local variable or method `feed' for #<#<Class:0x007f5644b79520>:0x007f5644b89858> 

<%= link_to 'checkout', feed.paypal_url(feeds_url) %>

有什么问题,我该如何解决这个错误?

更新

我只想将用于付款的按钮粘贴到我的网站,金额为 1 美元。我怎样才能做到?

【问题讨论】:

  • 在您的帖子中添加 feeds_controller 和 index.html.erb 的完整内容。

标签: ruby-on-rails paypal


【解决方案1】:

提要对象在哪里定义?如果在控制器中,那么它应该是像@feed 这样的实例变量,要从视图访问控制器中定义的变量,我们必须将它们定义为像@feed 这样的实例变量。

【讨论】:

    猜你喜欢
    • 2013-09-18
    • 2016-08-10
    • 2014-06-18
    • 2015-09-05
    • 2013-09-29
    • 1970-01-01
    • 1970-01-01
    • 2018-06-09
    • 1970-01-01
    相关资源
    最近更新 更多