編輯時will_paginate gem是不工作:我改變了代碼,現在改爲:導軌 - 使用。每次做
查看代碼:
<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'
該問題現在我正在收到錯誤:
@orders變量看起來是空的。你忘了傳遞will_paginate的集合對象嗎?
每當我點擊視圖中的訂單列表中的「顯示」鏈接。爲了以防萬一,嘗試重新啓動服務器,但無法讓它工作:S!
您應該使用'link_to'Show',order_path(order)'並確保'resources:orders'存在於您的路由中。 –
我試過了 - 和order_path(order.id)和資源:訂單已經在路由中 - 我已經將它移動到頂端,以確保它是第一個拾取的,但我仍然得到同樣的錯誤:S – ecs