我在我的Rails应用程序中使用ransack
gem进行高级搜索。如何过滤attribute_select
方法以不显示某些字段,例如id
和created_at
等。
= f.attribute_fields do |a|
= a.attribute_select
我上面的当前方法只列出了所有属性。
答案 0 :(得分:4)
根据Why your Ruby class macros (might) suck (mine did):
def self.ransackable_attributes(auth_object = nil)
super - ['id', 'created_at']
end
答案 1 :(得分:1)
您还可以定义可搜索的属性,而不是指定不可搜索的属性,如下所示:
def self.ransackable_attributes(auth_object = nil)
%w( searchable_attribute_goes_here another_one_goes_here ... ) + _ransackers.keys
end