I'm having a little problem with some search features for the Rails 3 site that I am developing. I have a simple model Postthat looks like this:
class Post < ActiveRecord::Base
acts_as_taggable
end
I use acts_as_taggable_onto add tags to my posts a little easier. When I have a message marked "rails" and I do the following, everything works well:
@posts = Post.tagged_with("rails")
Thing, I also want to find the title of the publication. When I have a message called "Hello world" and marked "rails", I want to find this post looking for "hello" or rails. Therefore, I need an operator LIKEfor the header column in combination with the method tagged_with acts_as_taggable_on. The area wheredoes not work because it is ORused instead AND.
I was hoping that would meta_searchfix the problem, but this does not work for me. I tried a few things. Here are two examples of what I have tried:
@search = Post.search(:tagged_with_or_title_like => params[:search])
@search = Post.search(:title_like => params[:search], :tagged_with => params[:search])
It just does not recognize tagged_with. This is my first time using it meta_search, so I might have done something wrong here .;) I read somewhere that it searchlogicworked in conjunction with acts_as_taggable_on, but since it does not support Rails 3, I cannot use it.
, - . - , acts_as_taggable_on meta_search? , , meta_search? , acts_as_taggable_on, meta_search, .:)
EDIT:
, tagged_with meta_search. :
Post.select("DISTINCT posts.*").joins(:base_tags).where("posts.title LIKE ? OR tags.name = ?", "%"+params[:search]+"%", params[:search])
, : acts_as_taggable_on meta_search. has_and_belongs_to_many. , , . , :
scope :search, lambda { |search| select("DISTINCT posts.*").joins(:tags).where("posts.title LIKE ? OR tags.name = ?", "%"+search+"%", search) }
:
Post.search(params[:search])
, . , - : , . , Google.