Created
January 4, 2012 20:12
-
-
Save murraycs/1561864 to your computer and use it in GitHub Desktop.
Search methods
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.prepare_params_for_search(params) | |
search = {}.merge(params) | |
search['metro_area_id'] = params[:metro_area_id] || nil | |
search['gender'] = params[:gender] || nil | |
search['state_id'] = params[:state_id] || nil | |
search['country_id'] = params[:country_id] || nil | |
search['skill_id'] = params[:skill_id] || nil | |
search['education'] = params[:education] || nil | |
search['bodytype'] = params[:bodytype] || nil | |
search['children'] = params[:children] || nil | |
search['smoking'] = params[:smoking] || nil | |
search | |
end | |
def self.build_conditions_for_search(search) | |
cond = Caboose::EZ::Condition.new | |
cond.append ['activated_at IS NOT NULL '] | |
if search['country_id'] && !(search['metro_area_id'] || search['state_id']) | |
cond.append ['country_id = ?', search['country_id'].to_s] | |
end | |
if search['state_id'] && !search['metro_area_id'] | |
cond.append ['state_id = ?', search['state_id'].to_s] | |
end | |
if search['metro_area_id'] | |
cond.append ['metro_area_id = ?', search['metro_area_id'].to_s] | |
end | |
if search['gender'] | |
cond.append ['gender = ?', search['gender'].to_s] | |
end | |
if search['education'] | |
cond.append ['education = ?', search['education'].to_s] | |
end | |
if search['bodytype'] | |
cond.append ['bodytype = ?', search['bodytype'].to_s] | |
end | |
if search['children'] | |
cond.append ['children = ?', search['children'].to_s] | |
end | |
if search['smoking'] | |
cond.append ['smoking = ?', search['smoking'].to_s] | |
end | |
if search['login'] | |
cond.login =~ "%#{search['login']}%" | |
end | |
if search['vendor'] | |
cond.vendor == true | |
end | |
if search['description'] | |
cond.description =~ "%#{search['description']}%" | |
end | |
cond | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment