Question

Regarding MetaSearch, I would like to extract "human" names from the search parameters. For example, when the params[:search] has non-blank values for the following:

- title_contains

- author_name_contains

I would like to extract:

- title

- author name

The end use would be to provide additional feedback to the user such as:

Results filtered on title and author name

I would like to use functions within the MetaSearch library to achieve this instead of re-developing the param parsing. While the above examples are simple in Ruby the MetaSearch parameter language can be expressive.

Thanks

Was it helpful?

Solution

If you really want to get these from the MetaSearch object, you can do something like:

@search.search_attributes.except('meta_sort').select {|k, v| v.present?}

I'm not really sure that you're gaining anything over pulling this from the params directly, though. In any real-world usage, you'd probably want to change the text you display based on the predicate.

You may want to tackle this using i18n, instead:

http://rdoc.info/github/ernie/meta_search/master/file/README.rdoc#Localization

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top