Confounding URL typists since 2007.

The latest on MetaSearch

Posted by Ernie on March 16, 2010 at 8:15 pm

Version 0.3.0 of MetaSearch is out. Changes since the last time I posted include additional view helpers for gathering array input, the addition of unit tests, and easier attribute and association exclusion that honors excluded attributes through associations.

check_boxes and collection_check_boxes

If you need to get an array into your where, and you don’t care about parameter order, you might choose to use a select or collection_select with multiple selection enabled, but everyone hates multiple selection boxes. MetaSearch adds a couple of additional helpers, check_boxes and collection_check_boxes to handle multiple selections in a more visually appealing manner. They can be called with or without a block, so something like this is possible when you want additional formatting around your check boxes:


How many heads?

    <% f.check_boxes :number_of_heads_in, [['One', 1], ['Two', 2], ['Three', 3]], :class => 'checkboxy' do |c| %>
  • <%= c[:check_box] %> <%= c[:label] %>
  • <% end %>

You can read more in the rdocs.

Excluding attributes and associations

If you’d like to prevent certain associations or attributes from being searchable, you can control this inside your models:

  class Article < ActiveRecord::Base
    metasearch_exclude_attr :some_private_data,
    metasearch_exclude_assoc :an_association_that_should_not_be_searched,

You get the idea. Excluded attributes on a model will be honored across associations, so if an Article has_many :comments and the Comment model looks something like this:

  class Comment < ActiveRecord::Base
    validates_presence_of :user_id, :body
    metasearch_exclude_attr :user_id

Then your call to will allow :comments_body_contains but not :comments_user_id_equals to be passed.

Filed under Blog
Tagged as , , ,
You can leave a comment, or trackback from your own site.