簡體   English   中英

Paypal集成在Rails應用中的不確定方法價格

[英]undefind method price in rails application with paypal integration

我正在與Rails3進行Paypal集成。我正在關注Railscast敏捷Web開發第4版。 但是我的運氣不好,我無法使其正常運行。

在我的carts / show.html.haml文件中,我具有以下內容

   %table
    %tr
      %th Product
      %th Qty
      %th Unit Price
      %th Full Price

    - for cart in @cart.line_items
      %tr
        %td= cart.product.title
        %td= cart.quantity
        %td= cart.price
        %td= cart.full_price
    = link_to "Continue Shopping", products_url 
    = link_to "Checkout", @cart.paypal_url(products_url) 

然后在我的app / model / cart.rb模型中,我有paypal方法

   has_many :line_items
   def paypal_url(return_url)
values = {
    :business => 'dev_1249899173_biz@gmail.com',
    :cmd => '_cart',
    :upload => 1,
    :return => return_url,
    :invoice => id
}
line_items.each_with_index do |item, index|
  values.merge!({
                    "amount_#{index+1}" => item.price,
                    "item_name_#{index+1}" => item.product.title,
                    "item_number_#{index+1}" => item.id
                    #"quantity_#{index+1}" => item.quantity
                })
end
"https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query

結束

但是我進入購物車頁面時出現以下錯誤

 undefined method `price' for line_items

我猜這個錯誤是由於購物車模型中的貝寶方法受阻

    line_items.each_with_index do |item, index|
    values.merge!({
                    "amount_#{index+1}" => item.price,
                    "item_name_#{index+1}" => item.post.title,
                    "item_number_#{index+1}" => item.id
                    #"quantity_#{index+1}" => item.quantity
                }) 

實際上,我不知道這些line_items是如何觸發的,這些值是從哪里來的。

請幫助我了解並解決此錯誤。 我是新手。

不知道你如何定義你的LINE_ITEM(產品),但我想你應該叫cart.product.price模型,我認為,你叫full_pricecart ,如果cart的人line_item不應該保持車的總價格,你應該通過@cart.full_price獲得。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM