I have a materials model which has a search form. The search action looks a bit like this:
def search
conditions = {}
conditions[:version] = 'master'
conditions[:status] = 'shared'
conditions[:targ_lang] = params[:targ_lang] unless params[:targ_lang].blank?
@results = Material.find(:all, :conditions => conditions)
end
I have added the acts-as-taggable gem and it works fine to save the tags but I'm having trouble adding it to the search form. The documentation states that to find Materials with the tags you can use this code:
Material.tagged_with(["awesome", "cool"], :match_all => true)
But I don't know how to add this condition to the conditions.
Update
@results = Material.where(conditions) && Material.tagged_with(params[:tag_list])
This works provided tags are used but it doesn't work if the tag list is blank so I need a condition as with the other conditions above that the Material.tagged_with ... part is only necessary if the field is not empty.
Update 2 - Bad Solution
This works but it's not very elegant is it?
if params[:tag_list].blank?
@results = Material.where(conditions)
else
@results = Material.tagged_with(params[:tag_list]).where(conditions)
end