Created
September 26, 2011 23:23
-
-
Save batasrki/1243741 to your computer and use it in GitHub Desktop.
Example model search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Job < ActiveRecord::Base | |
def self.search(search, page=1, cond, join) | |
condition = (cond) ? " AND #{cond}" : "" | |
if join | |
paginate :per_page => 10, :page => page, :joins => join, | |
:order => 'jobs.name', :conditions => "(#{search})#{condition}" | |
else | |
paginate :per_page => 10, :page => page, | |
:order => 'name', :conditions => "(#{search})#{condition}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment