我有一个应用程序,其中有两个模型:debates
和challenges
.
每个模型都有一个标题,我acts_as_taggable
在两者上都使用。
我有一个搜索表单,可以在其中搜索每个标签:
看法
<%= form_tag ("/search_results"), :method => "get", :id=>"search-form" do %>
<%= text_field_tag ("search") , nil, :id=>"search-text",
:onblur=>"if(this.value=='')this.setAttribute('class', 'search_input');",
:onfocus=>"this.setAttribute('class', 'search_input_clear');",
placeholder: "Chercher un débat"
%>
<% end %>
在我的控制器上:
def search_results
@challenges = Challenge.tagged_with("#{params[:search]}")
@debates = Debate.tagged_with("#{params[:search]}")
@lists = @debates + @challenges
end
问题是,如何在同一搜索标签中结合标签搜索和标题搜索?