Home > like_searchable_on

like_searchable_on

Like_searchable_on is a project mainly written in Ruby, it's free.

Just a ghetto-ass way to include basic crappy sql find where field like '%term%' functionality into a model.

Probably pretty hellacious performance-wise, but works fine for low-traffic areas of an app like admin.

Use simply by declaring within your model: searchable_on [ :field_to_search, :another_fieled_to_search ]

You will get a class method called .search that takes a search term as it's only argument. It will search the fields in the model declared in the searchable_on argument array, and return an active record relation (so it can be scoped, chained, etc.).

Example

class User searchable_on [ :name, :email, :interests ] ... end

results = User.search( 'bob' )

returns users who have a name like '%bob%' or email like '%bob%' or interests like '%bob%'

Can also do results = User.search( 'bob' ).active.happy

That is all.

Copyright (c) 2010 Gk Parish-Philp, released under the MIT license

Previous:tiny-pong