如何将PGSeaerch结果链接到嵌套资源中的索引页面?

我终于想出了如何实现pg_search的multiisearchfunction。

但是我在制作一个可用的搜索页面时遇到了麻烦,该页面显示了返回相应嵌套页面的链接。

如何传递正确的ID,以便链接到嵌套视图。

所以类似于link_to

myapp.com/artists/1/albums 

到目前为止,我得到了这个错误(我似乎无法通过艺术家ID)

 No route matches {:controller=>"albums", :artists=>nil} 

Rails的新手请帮忙:)

CONTROLLERS

 class ResultsController  params[:page] ) @artists = PgSearch.multisearch(params[:query]).where(searchable_type: "Artist") @albums = PgSearch.multisearch(params[:query]).where(searchable_type: "Album") end end 

VIEWS

   
Artists
#### How can I link to the Albums index page
Albums
####How can I link to the Albums index page

楷模

 class Artist  :albums include PgSearch multisearchable :against => [:name], using: {tsearch: {dictionary: "english"}} end class Album  [:name], using: {tsearch: {dictionary: "english"}} associated_against: {artist: [:artist_id, :name]} end 

ROUTES

 Music::Application.routes.draw do resources :artist do resources :albums end resources :results end 

SCHEMA

 create_table "pg_search_documents", :force => true do |t| t.text "content" t.integer "searchable_id" t.string "searchable_type" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false end 

这是我链接到索引页面的解决方案。 有点麻烦,如果有人有一个更容易的解决方案。 请发表评论:)

  <% @results.each do |pg_results| %> <% if pg_results.searchable_type == "Artist" %> 
#### This is how I linked to the ALBUMS INDEX <%= link_to pg_results.searchable.name, {:action => "index", controller => "albums", :artist_id => => pg_results.searchable}
<% end %> <% end %>