我正在尝试使用rails实现Paypal集成。在此之后(http://railscasts.com/episodes/141-paypal-basics)我在模型中有一个函数,它使用返回URL调用paypal服务。我在视图中添加了一个链接到模型中方法的链接。但是一些rails如何无法在模型中获取函数。
我做错了什么?
我的观点:
form_for @order do |f|
- if @order.errors.any?
#error_explanation
h2 = "#{pluralize(@order.errors.count, "error")} prohibited this order from being saved:"
ul
- @order.errors.full_messages.each do |message|
li = message
.field
= f.label :first_name
= f.text_field :first_name
.field
= f.label :last_name
= f.text_field :last_name
.field
= f.label :card_number
= f.text_field :card_number
.field
= f.label :card_verification, "Card Verification Value (CVV)"
= f.text_field :card_verification
.field
= f.label :card_expires_on
= f.date_select :card_expires_on, {start_year: Date.today.year, end_year: (Date.today.year+10), add_month_numbers: true, discard_day: true}, {class: "browser-default"}
.field
= link_to 'PayPal', @order.paypal_url(current_user)<= link to model function
.actions
= f.submit
我的模型:定义了以下功能。
def paypal_url(return_url)
values = {
:business => 'xxxxx.XXXXX@techflex.com',
:cmd => '_cart',
:upload => 1,
:return => return_url,
:invoice => id
}
values.merge!({
"amount_#{1}" => item.unit_price,
"item_name_#{1}" => item.product.name,
"item_number_#{1}" => item.id,
"quantity_#{1}" => item.quantity
})
"https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query
端
错误:
NoMethodError in Orders#new
Showing C:/Users/Suniljadhav/SourceCode/TrainStation/app/views/orders/_form.html.slim where line #24 raised:
private method `paypal_url' called for #<Order:0x5e49bf8>
Trace of template inclusion: app/views/orders/new.html.slim
Rails.root:C:/ Users / Suniljadhav /源代码/ TrainStation