0

我添加了 will_paginate gem,它在网站的所有其他区域都运行良好。但是,每当我尝试单击视图中的“显示”链接以链接到订单时,都会出现以下错误消息: * @orders 变量似乎为空。您是否忘记传递 will_paginate 的集合对象?*

任何人都知道为什么会发生这种情况以及我该如何解决?我试过重启服务器。谢谢!!

查看代码:

<h3>Your Orders:</h3>
<table class="order-items">
  <th>Date</th>
  <th>Order No.</th>
  <th>View Order</th>
<% @orders.each do |order| %>
<tr>
    <td><%= order.created_at.strftime("%d %b. %Y") %></td>
    <td><%= order.id %></td>
    <td><%= link_to 'Show',  order_path(order) %></td>
</tr>
<% end %>   
</table>

<p><%= will_paginate @orders %></p>

控制器代码:

@customer = Customer.find(params[:id])
@orders = @customer.orders.paginate page: params[:page], order: 'id desc',
  per_page: 5

路线:

resources :orders

resources :customers

get 'admin' => 'admin#index'

get 'account' => 'customers#show'

match '/account', :to => 'customers#show'

match'/signup', :to => 'customers#new'

controller :sessions do
  get  'login' => :new
  post 'login' => :create
  delete 'logout' => :destroy
end


resources :users

resources :line_items

resources :carts

get "store/index"

resources :products do
  get :who_bought, on: :member
end

resources :line_items do
  put 'decrease', on: :member
  put 'increase', on: :member
end

root to: 'store#index', as: 'store'
4

0 回答 0