[英]rails 4 will_paginate custom records second page not showing
I have created a custom search of books according to the criteria the user enters and I use will_paginate to show them. 我已经根据用户输入的条件创建了自定义图书搜索,并使用will_paginate进行显示。 However, even though the first page shows ok, when I choose the second the following error message appears:
但是,即使第一页显示确定,当我选择第二页时,也会出现以下错误消息:
Couldn't find Book with id=show_search_by_title` in show method
def show
@book = Book.find(params[:id])
authorize! :read, @book
end
In the books_controller there is the following method: 在books_controller中,有以下方法:
def show_search_by_title
q = params[:book][:title]
books = Book.where('title LIKE ?', "%#{q}%")
@books = books.paginate(page: params[:page], per_page: 10)
end
and the corresponding .erb file is the following: 相应的.erb文件如下:
<% if @books.empty? %>
There are no books in the Library that fulfill the given criteria
<% else %>
<%= will_paginate @books %>
The books that complete the given criteria are the following: 满足给定条件的书籍如下:
<table>
<tr>
<th> Book Title </th> <th> Author </th> <th> Category </th> <th> copies </th> <th> Rank </th>
</tr>
<% @books.each do |book| %>
<tr>
<td><%=book.title %> </td>
<td><%=book.author.name %> </td>
<td><%=book.cat.description %></td>
<td><%=book.copies %> </td>
<td><%=book.rank %> </td>
</tr>
<% end %>
</table>
<%= will_paginate @books %>
<% end %>
Thank you very much in advance. 提前非常感谢您。
my routes for books are: 我的上书路线是:
view_books_books_path GET /books/view_books(.:format) books#view_books
rank_book_books_path GET /books/rank_book(.:format) books#rank_book
update_book_rank_books_path PATCH /books/update_book_rank(.:format) books#update_book_rank
search_by_title_books_path GET /books/search_by_title(.:format) books#search_by_title
search_by_author_books_path GET /books/search_by_author(.:format) books#search_by_author
show_search_by_title_books_path GET /books/show_search_by_title(.:format) books#show_search_by_title
show_search_by_author_books_path POST /books/show_search_by_author(.:format) books#show_search_by_author
books_path GET /books(.:format) books#index
POST /books(.:format) books#create
new_book_path GET /books/new(.:format) books#new
edit_book_path GET /books/:id/edit(.:format) books#edit
book_path GET /books/:id(.:format) books#show
shows the error in show method: 在show方法中显示错误:
def show
@book = Book.find(params[:id])
authorize! :read, @book
end
You need to specify the action in the options for will_paginate https://github.com/mislav/will_paginate/wiki/API-documentation#will_paginatecollection-options . 您需要在will_paginate https://github.com/mislav/will_paginate/wiki/API-documentation#will_paginatecollection-options的选项中指定操作。 What is the path of the link for the "next" button?
“下一步”按钮的链接路径是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.