Frage

I'm using the ransack gem with my Rails application for an advanced search. How can I filter the attribute_select method to not show certain fields such as id and created_at, etc.

= f.attribute_fields do |a|
  = a.attribute_select

My current method above simply lists any and all attributes.

War es hilfreich?

Lösung

According to Why your Ruby class macros (might) suck (mine did):

def self.ransackable_attributes(auth_object = nil)
  super - ['id', 'created_at']
end

Andere Tipps

You can also define the searchable attributes versus specifying the non-searchable ones like so:

def self.ransackable_attributes(auth_object = nil)
    %w( searchable_attribute_goes_here another_one_goes_here ... ) + _ransackers.keys
end
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top