Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 私有方法`总价';要求#<;行项目:_Ruby On Rails_Private_Depot - Fatal编程技术网

Ruby on rails 私有方法`总价';要求#<;行项目:

Ruby on rails 私有方法`总价';要求#<;行项目:,ruby-on-rails,private,depot,Ruby On Rails,Private,Depot,我正在使用Depot tutorial,在定义总价时遇到了一个问题: 这就是我得到的错误:有人知道它出了什么问题吗?多谢各位 NoMethodError in Carts#show Showing C:/pan/app/views/carts/show.html.erb where line #7 raised: private method `total_price' called for #<LineItem:0x3ed2640> Extracted source (arou

我正在使用Depot tutorial,在定义总价时遇到了一个问题: 这就是我得到的错误:有人知道它出了什么问题吗?多谢各位

NoMethodError in Carts#show

Showing C:/pan/app/views/carts/show.html.erb where line #7 raised:

private method `total_price' called for #<LineItem:0x3ed2640>
Extracted source (around line #7):

4: <tr>
5: <td><%= item.quantity %>&times;</td>
6: <td><%= item.product.brand %></td>
7: <td class="item_price" ><%= number_to_currency(item.total_price) %></td>
8: </tr>
9: <% end %>
10: <tr class="total_line" >
NoMethodError in Carts#show
显示C:/pan/app/views/carts/show.html.erb,其中第7行出现:
调用私有方法“总价”#
提取的源(第7行附近):
4: 
5:&次;
6: 
7: 
8: 
9: 
10: 

确保此方法的定义不在LineItem类中的
private
关键字下,否则它被视为private,不允许在类外调用。

谢谢@Semyon Perepelitsa,我修改了LineItem类,将方法的定义移动到“private”关键字上方,它可以工作。非常感谢。