레일과 페이팔 통합을 달성하려고합니다. 이 (http://railscasts.com/episodes/141-paypal-basics) 다음에 반환 URL로 페이팔 서비스를 호출하는 모델에 함수가 있습니다. 모델의 함수에 링크되는 뷰의 링크를 추가했습니다. 그러나 레일에서 모델의 함수를 가져올 수없는 방법도 있습니다.Ruby on 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 => '[email protected]',
: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 :/사용자/Suniljadhav/소스 코드 /는 trainstation은
어떤 오류가 발생하고 있습니까? – mlovic
@ mlovic : 내 질문에 오류가 있습니다. –