我第一次安裝了pg_search,並且正在嘗試創建書籍和章節的搜索。這些是嵌套路線。帶嵌套路線的pg_search
的routes.rb:
resources :books do
resources :chapters, except: [:index]
end
pgsearch結果顯示的鏈接信息,但各章節的鏈接顯示/章節/ 17,當它應該顯示/書籍/ 50 /章節/ 17。
搜索索引視圖:
<h2>
<% @pg_searches.each do |pg_search| %>
<p> <%= link_to pg_search.searchable.title, pg_search.searchable %> </p>
<% end %>
<h2>
SearchesController
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
我如何得到正確的路線找不到書?
這個伎倆! – jgrant