ruby-on-railsviewfiltermeta-search

Rails meta-search: Check if filter is set


Is it possible to check if a filter on a search-object from the rails gem meta-search is set? I've got this code in my controller:

@search = Tree.search(params[:search])

when i do @search.search_attributes.empty? i got true if i the form never has been sent. But if i send the form, even if its blank i get false (which is logic)

What is the best solution to check (from the view) if there is no filter active?

I hope someone can help me with this, thanks!


Solution

  • Instead of empty u can check using present.

    @search.search_attributes.present?