Created
December 16, 2010 07:26
-
-
Save joshrendek/743156 to your computer and use it in GitHub Desktop.
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
def self.search(term, per_page, page, subdomain_id) | |
conditions, conditional = Array.new, Array.new | |
# made prettier by an array and a join | |
self.column_names.collect { |c| c != "subdomain" ? conditional << "#{c} LIKE '%%%s%%'" : "" } | |
# wrap around SQL logic for making sure search only returns results pertinent to domain | |
conditions.push("(" + conditional.join(' OR ') + ") AND subdomain = '#{subdomain_id}'") | |
# push the search term into the conditions -- replacing the %%s%% | |
self.column_names.size.times { conditions.push(term) } | |
#clean the sql | |
conds = sanitize_sql_array(conditions) | |
#paginate the result | |
self.paginate(:all, :conditions => conds, :per_page => per_page, :page => page) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment