如何在传递不同变量的同一部分上使用分页?
我的Rails应用程序中有一个库显示页面,其中包含一系列书籍:
libraries_controller.rb:
def show
@books = @library.books.paginate(page: params[:books_page], per_page: 10)
end
库/ show.haml:
#books_table
= render "books_list", books: @books
库/ show.js.erb:
$('#books_table').replaceWith('<%= j render "books_list", books: @books %>');
A&#39; books_list&#39; partial有一个分页链接,工作正常:
书籍/ _books_list.haml:
...
= paginate books, param_name: 'books_page'
当我向列表中添加新书时,#books_table
会自动替换为_books
部分,如此(books / create.js.erb):
$('#books_table').replaceWith('<%= j render "libraries/books_list", books: @library_books%>')
books_controller.rb:
def create
@library_book = @library.books.create(book_params)
@library_books = @library.books.paginate(page: params[:books_page], per_page: 10)
end
但在这一点上,分页并不起作用。任何想法我该怎么办?