0
我已經得到了一個任務做pagination.When我這樣做分頁我已經得到了這些錯誤分頁在Ruby on Rails的
NoMethodError in ProductsController#index
undefined method `page' for []:ActiveRecord::Relation
Rails.root: /home/nithinv/store
Application Trace | Framework Trace | Full Trace
app/controllers/products_controller.rb:4:in `index'
這是我的控制器
def index
@products = Product.order(:name).page(params[:page]).per(2)
respond_to do |format|
format.html #index.html.erb
format.json { render :json=> @products }
end
end
這是我的索引。 html.erb
<% title "Products" %>
<%= paginate @products %>
<% for product in @products %>
<div class="product">
<h2><%= link_to product.name, product %></h2>
<div class="details">
<%= number_to_currency(product.price) %> |
Released <%= product.released_at.strftime("%B %e, %Y") %>
</div>
</div>
<% end %>
<p><%= link_to "New Product", new_product_path %></p>
我該如何解決這個問題?