This plugin allows you to search in your models on each of its attributes using wild cards. The default behavior is to chain the search parameters using “or” and wild cards in both sides. This behavior can be changed by adding the :clause=>“and” and the :left=>true or :right=>true parameters
gem 'act_as_wild_searchable', :git => 'http://github.com/canimus/acts_as_wild_searchable-0.0.1.gem'
bundle install
-
Rails 3.2.3
-
the
_like?
methodConsider that you model has the name attribute
User.name_like? "John"
-
the
chain
capabilitiesTo chain various queries just add another query after the usage of the like? method
User.name_like?("John").where(:id => 1)
-
the
multiple_search
You can add as many clauses and by default will be added using an “or” clause
User.name_like? "John","David", "Peter" # Produces where (name like ? or name like ? or name like ?, "%John%", "%David%", "%Peter%")
-
the
left
You can position the wild card with a hash addition to the call
User.name_like? "John","David", :left => true # Produces where (name like ? or name like ?, "%John", "%David")
-
the
right
You can position the wild card with a hash addition to the call
User.name_like? "John","David", :right => true # Produces where (name like ? or name like ?, "John%", "David%")
-
the
clause
You can change the default behavior for the wild card search by addint the clause hash
User.name_like? "John","David", :clause => "and" # Produces where (name like ? and name like ?, "%John%", "%David%")
You can configure the following attributes that will locate the wild card for your search
left # false by default right # false by default clause # "or" by default