Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 带嵌套路由的pg_搜索_Ruby On Rails_Pg Search - Fatal编程技术网

Ruby on rails 带嵌套路由的pg_搜索

Ruby on rails 带嵌套路由的pg_搜索,ruby-on-rails,pg-search,Ruby On Rails,Pg Search,我第一次安装了PGU搜索,我正在尝试创建一个图书和章节搜索。这些是嵌套的路由 routes.rb: resources :books do resources :chapters, except: [:index] end pgsearch results显示指向信息的链接,但chapters链接显示/chapters/17,此时应显示/books/50/chapters/17 搜索索引视图: <h2> <% @pg_searches.each do |pg_sear

我第一次安装了PGU搜索,我正在尝试创建一个图书和章节搜索。这些是嵌套的路由

routes.rb:

resources :books do
  resources :chapters, except: [:index]
end
pgsearch results显示指向信息的链接,但chapters链接显示/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
include PgSearch
 multisearchable :against => [:title, :body]
book.rb

include PgSearch
 multisearchable :against => [:title, :description]
以下是错误消息:

resources :books do
  resources :chapters, except: [:index]
end
找不到没有ID的书

def show
 **@book = Book.find(params[:book_id])**
 @chapters = Chapter.all
 @chapter = Chapter.find(params[:id])
 @table_of_contents = @chapter.table_of_contents
我怎样才能找到正确的路线

我想,你需要试试
或者检查类似的

我认为您的链接路径缺少父对象,因此无法形成正确的url。因为路由器需要一个
books/:id/chapters/:id
格式的URL,我们还需要将
link\u传递给图书对象的chapter

试试这个:


尝试关联\u,但仍然收到相同的结果。