我想要获取所有主题名称将与搜索关键字匹配的配置文件。现在我正在加载所有配置文件。我需要知道我该如何实现它。任何帮助深表感谢。如何通过导轨中的关联进行搜索4
Profile.rb
has_many :categorizations
has_many :subjects, through: :categorizations
subject.rb中
has_many :categorizations
has_many :profiles, through: :categorizations
Categorization.rb
belongs_to :profile
belongs_to :subject
意见/搜索/ index.html.erb
# search form
<%= form_tag search_index_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "search", :name => nil %>
<% end %>
# search results
<% @profiles.each do |profile| %>
<%= profile.name %>
<% end %>
search_controller.rb
def index
@profiles = Profile.with_translations('en').all
end
你需要搜索的关键字精确匹配的轮廓主题? – Teddy
不完全相同,如果主题名称上的词匹配比静态配置文件应显示在搜索结果中。 – Murtza