【发布时间】:2012-10-27 21:29:09
【问题描述】:
我在我的 Rails 应用程序中使用 ransack gem 进行高级搜索。如何过滤attribute_select 方法以不显示某些字段,例如id 和created_at 等。
= f.attribute_fields do |a|
= a.attribute_select
我上面的当前方法只是列出了所有属性。
【问题讨论】:
标签: ruby-on-rails ransack
我在我的 Rails 应用程序中使用 ransack gem 进行高级搜索。如何过滤attribute_select 方法以不显示某些字段,例如id 和created_at 等。
= f.attribute_fields do |a|
= a.attribute_select
我上面的当前方法只是列出了所有属性。
【问题讨论】:
标签: ruby-on-rails ransack
根据Why your Ruby class macros (might) suck (mine did):
def self.ransackable_attributes(auth_object = nil)
super - ['id', 'created_at']
end
【讨论】:
您还可以定义可搜索的属性而不是指定不可搜索的属性,如下所示:
def self.ransackable_attributes(auth_object = nil)
%w( searchable_attribute_goes_here another_one_goes_here ... ) + _ransackers.keys
end
【讨论】: