通过不同变量的相同部分的分页(will_paginate)

时间:2016-07-13 12:10:52

标签: ruby-on-rails pagination partial-views will-paginate

如何在传递不同变量的同一部分上使用分页?

我的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

但在这一点上,分页并不起作用。任何想法我该怎么办?

0 个答案:

没有答案