Topic: Help improving this search code

@customers = Customer.find(:all, 
    :conditions => "(customers.studio_id = #{session[:studio_id]}) AND (" + Customer.conditions_by_like(params[:search], :c1_name, :c2_name) + ")",
   :include => [:events, :customer_state])

There has to be a way to get that first part (studio_id) in nicely with the conditions_by_like... but I can't figure it out. Little help?!

Last edited by twild (2007-07-21 23:14:02)

Re: Help improving this search code

You could use acts_as_ferret.

You could also do @customers = Customer.find_by_studio_id(session[:studio_id], :conditions => ...)

Re: Help improving this search code

Acts as ferret is great to know about, but is probably overkill for this, thanks. I really just want to tidy up my code a little.

Your find_by_studio_id suggestion was perfect, something I overlooked, and worked better when I used find_all_by_studio_id (i'm still new to rails).

Thanks again! smile