我对使用高级洗劫搜索有点困惑。我正在尝试进行自定义搜索,其中并非所有表名都可以选择作为搜索词,并且并非所有谓词都被使用。我使用railscast作为教程,但我找不到任何限制谓词数量的方法。是否也可以使用不同语言的谓词和表字段的名称(只是标签)?
我的搜索表格
= search_form_for @q, :url => search_offers_path, :html => { :method => :post } do |f|
= f.condition_fields do |c|
.field
= f.attribute_fields do |a|
= a.attribute_select
= f.predicate_select
= f.value_fields do |v|
= v.text_field :value
= link_to "#{t :destroy}", '#', class: "remove_fields"
= link_to_add_fields "#{t :add}", f, :condition
.field
= t :sort
= f.sort_fields do |s|
= s.sort_select
= f.submit "#{t :search}"
我的控制器
def index
select_offers = Offer.where { (user_id != id) & (ended == false) & ((created_at + life_time ) > DateTime.now) }
@q = select_offers.search(params[:q])
@offers = @q.result(:distinct => true).page(params[:page])
@q.build_condition
@q.build_sort if @q.sorts.empty?
end