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'