【发布时间】:2015-11-05 17:41:10
【问题描述】:
我是第一次安装 pg_search,我正在尝试创建对书籍和章节的搜索。这些是嵌套路由。
routes.rb:
resources :books do
resources :chapters, except: [:index]
end
pgsearch 结果显示信息的链接,但章节链接显示 /chapters/17,而它应该显示 /books/50/chapters/17。
搜索索引视图:
<h2>
<% @pg_searches.each do |pg_search| %>
<p> <%= link_to pg_search.searchable.title, pg_search.searchable %> </p>
<% end %>
<h2>
搜索控制器
class SearchesController < ApplicationController
def index
@pg_searches = PgSearch.multisearch(params[:query])
end
end
chapter.rb
include PgSearch
multisearchable :against => [:title, :body]
book.rb
include PgSearch
multisearchable :against => [:title, :description]
错误信息如下:
找不到没有 ID 的书
def show
**@book = Book.find(params[:book_id])**
@chapters = Chapter.all
@chapter = Chapter.find(params[:id])
@table_of_contents = @chapter.table_of_contents
如何获得正确的路线?
【问题讨论】: