I have a view page .html.erb
in rails which displays the list of attachments (pulled from array) uploaded by a particular user. This view page has a Delete
button at the end of the page (which deletes all the attachments selected by the user). I want to paginate this page. I want the delete button to be present along with pagination. I have tried removing button and form_for()
in this page, then pagination worked. But when i include both, it throws an error
"undefined method `model_name' for ActiveRecord::Relation:Class"
please suggest some methodology to overcome this problem.
In controller file first include the paginate
-
def index
@orders = Order.paginate(:page => params[:page], order: 'created_at desc', :per_page => 5)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @orders }
end
end
and in view file use as
<%= will_paginate @order_items %>
may this code will help to remove your errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.