0
我有一個song.rb模型和genre.rb模型,我希望能夠搜索。添加了輪胎搜索寶石,如何添加多個索引?
由於某種原因,輪胎只返回歌曲而非流派的搜索結果。
的代碼:
genre.rb
class Genre < ActiveRecord::Base
has_many :genre_songs, :dependent => :destroy
has_many :songs, through: :genre_songs
include Tire::Model::Search
include Tire::Model::Callbacks
end
song_controller SNIPPIT
def index
if params[:query].present?
@songs = Song.search(params[:query], load: true)
elsif params[:genre]
@songs = Song.tagged_with(params[:genre]).paginate(:page => params[:page], :per_page => 15)
get_last_song
else
@songs = Song.order('id').order('plusminus desc nulls last').paginate(:page => params[:page], :per_page => 15)
#@songs = Song.tally.paginate(:page => params[:page], :per_page => 15)
get_last_song
end
end
song.rb SNIPPIT
include Tire::Model::Search include Tire::Model::Callbacks
個index.html.erb SNIPPIT
<%= form_tag songs_path, method: :get do %>
<p>
<%= text_field_tag :query, params[:query] %>
<%= submit_tag "Search", name: nil %>
</p>
<% end %>