Ruby on rails Rails-通过单个文本字段使用元搜索/搜索
有人知道是否可以将Metasearch/Ransack gem与单个文本字段而不是多个文本字段一起使用吗?对于我的应用程序,我只想在我的模型中搜索两个相关属性,而全文搜索似乎有些过分。无论如何,任何帮助都将不胜感激 当然可以。下面的代码包含4个字段,但您只能有一个字段。这里有一个很好的资源(railscast),但很快就会进入您试图避免的搜索的高级方面: 控制器Ruby on rails Rails-通过单个文本字段使用元搜索/搜索,ruby-on-rails,search,Ruby On Rails,Search,有人知道是否可以将Metasearch/Ransack gem与单个文本字段而不是多个文本字段一起使用吗?对于我的应用程序,我只想在我的模型中搜索两个相关属性,而全文搜索似乎有些过分。无论如何,任何帮助都将不胜感激 当然可以。下面的代码包含4个字段,但您只能有一个字段。这里有一个很好的资源(railscast),但很快就会进入您试图避免的搜索的高级方面: 控制器 def search @search = Entry.search(params[:q]) @entries = @searc
def search
@search = Entry.search(params[:q])
@entries = @search.result
end
视图(haml)
具体来说,使用:attrib1_或\u attrib2_条件,就像@Danny在他的第一个文本_字段中所做的那样。
%h1 Search
= search_form_for @search, :url=>search_entries_path do |f|
.field
=f.label :make_or_model_cont, "Make or Model"
=f.text_field :make_or_model_cont
.field
=f.label :last_four_cont, "Last Four contains"
=f.text_field :last_four_cont
.field
=f.label :created_at_gt, "Date after"
=f.text_field :created_at_gt, :class=>"scroller time_field" # using jquery datetime picker plugin
.field
=f.label :created_at_lt, "Date is before"
=f.text_field :created_at_lt, :class=>"scroller time_field"
.actions
=f.submit "Search"
=render 'results' # contains table, ths and tr + tds to hold the data