I am quite new to Rails and I can't seem to get my head around this:
I have various Projects belonging to various Clients.
In my Project model I have two search functions:
scope :search_by_name, lambda { |fn| where('name LIKE ?', "%#{fn}%") }
scope :search_by_client, lambda { |fn| where('client_id LIKE ?', fn) }
Both seem to work. For example in the URL I can pass in this query:
/projects?search_by_name=fooproject
I can equally do this:
/projects?search_by_client_name=misterx
This will yield all the Projects belonging to the Client MisterX.
Now is there a way to combine these two search functions so that a query
/projects?search=foofoo
will retrieve Projects named foofoo as well as projects belonging to Clients named foofoo?
Thanks for any help!
@projects = current_user.projects.search_by_name(params[:name]).search_by_client(params[:client])