0

레일과 페이팔 통합을 달성하려고합니다. 이 (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은

+1

어떤 오류가 발생하고 있습니까? – mlovic

+0

@ mlovic : 내 질문에 오류가 있습니다. –

답변

0

paypal_url 개인 방법과 것 같다 그것의 종류의 외부에서 그것을 부르는 것을 시도하고있다.

Order 클래스에는 아마도 private이라는 키워드가 있습니다. 해당 키워드 아래의 모든 메소드는 private (public과 반대)로 선언되며 클래스 외부에서 호출하려고하면 오류가 발생합니다. private 메소드는 정의 된 클래스 내에서만 호출 할 수 있습니다. 따라서 paypal_url의 정의를 이동하여 클래스에 private 앞에 나타나도록하십시오.

자세한 내용은 here과 이에 대한 이유는 here을 참조하십시오.

+0

: 어리석은 짓을하고 있었는데, 혼자서 알아 내야 했어. 어떤 방법으로도 도움을 주셔서 감사합니다. –