Sha256: 43a58f5cefe7e50034e811c726963afef5a17b4488d35865fa16c7729ad716cd

Contents?: true

Size: 1.49 KB

Versions: 26

Compression:

Stored size: 1.49 KB

Contents

SearchableBy
============

Adds a search method to query your ActiveRecord models:

searchable_by :field_a, :field_b, :field_etc

YourModel.search 'some search words'

Examples
========

# declare with searchable_by
class User < ActiveRecord::Base
  enables the "search" method and by default searches 'login' and 'email' columns
  searchable_by :login, :email
end

# search into associations
class User < ActiveRecord::Base
  has_many :addresses
  searchable_by :login, :email, :addresses => [:street, :city]
end

# simple search - based on default fields in searchable_by line
User.search 'fred'
=> [#<User>, #<User>]

# specify which fields to search on with :narrow_fields
User.search 'fred', :narrow_fields => [:email, :login, :name]
=> [#<User>, #<User>, #<User>]

# use default search fields but pass other options
User.search 'fred', :conditions => { :is_admin => true }, :limit => 2
=> [#<User>, #<User>]

# use :page option and we'll assume that you want to paginate using will_paginate
User.search 'j', :page => 2
=> [#<User>, #<User>, #<User>, #<User>, #<User>]

# by default, all search words must be found
User.search 'fred john jack susan'
=> []

# set :require_all to false if you want to do an "OR" search
User.search 'fred john jack susan', :require_all => false
=> [#<User>, #<User>, #<User>, #<User>, #<User>]

# use double quotes to identify phrases
User.search '"fred flintstone"', :narrow_fields => [:login, :full_name]
=> [#<User>]



Copyright (c) 2008-2009 Jason LaPier, released under the MIT license

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
event_calendar_engine-0.2.15 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.14 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.13 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.11 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.10 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.8 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.7 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.6 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.5 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.4 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.3 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.2 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.1 vendor/plugins/searchable_by/README
event_calendar_engine-0.2.0 vendor/plugins/searchable_by/README
event_calendar_engine-0.1.11 vendor/plugins/searchable_by/README
event_calendar_engine-0.1.10 vendor/plugins/searchable_by/README
event_calendar_engine-0.1.9 vendor/plugins/searchable_by/README
event_calendar_engine-0.1.8 vendor/plugins/searchable_by/README
event_calendar_engine-0.1.7 vendor/plugins/searchable_by/README
event_calendar_engine-0.1.6 vendor/plugins/searchable_by/README