Im newbie on ruby on rails) Ok, I have controller with index action:
def index
condition = ['fulltime','parttime','remote','forone']. select{ |t| params.has_key?(t.to_sym) }.join(' | ')
Advert.search params[:search],:order => :created_at, :sort_mode => :desc, :conditions => {:employment_type=>condition}
But it peace of code:
['fulltime','parttime','remote','forone']. select{ |t| params.has_key?(t.to_sym) }
return nil
Why?:))
I don't want to write code with a bunch of checks like:
if !fulltime.nil? && !fulltime.blank?
condition = "fulltime"
end
if !parttime.nil? && !parttime.blank?
if !condition.nil? && !condition.blank?
condition = condition + " | parttime"
else
condition ="parttime"
end
end
But my way with array.select method is not working:(
Could you give me some advices?) Thanks!