我添加了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'