Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6106343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:04:09+00:00 2026-05-23T14:04:09+00:00

I’ve run into a small problem with some search-functionality for a Rails 3 website

  • 0

I’ve run into a small problem with some search-functionality for a Rails 3 website I’m developing. I have a simple Post model that looks like this:

class Post < ActiveRecord::Base
  acts_as_taggable
end

I’m using acts_as_taggable_on to make adding tags to my posts a bit easier. When I have a post tagged ‘rails’ and I do the following, all works well:

@posts = Post.tagged_with("rails")

Thing is, I also want to search for the title of the post. When I have a post titled ‘Hello world’ and tagged ‘rails’, I want to be able to find this post by searching for ‘hello’ or ‘rails’. So I want a LIKE statement for the title column in combination with the tagged_with method acts_as_taggable_on provides. The where scope doesn’t work, because it uses AND instead of OR.

I hoped meta_search would fix the problem, but this isn’t working for me. I tried several things. Here are two examples of what I tried:

@search = Post.search(:tagged_with_or_title_like => params[:search])
@search = Post.search(:title_like => params[:search], :tagged_with => params[:search])

It just doesn’t recognize ‘tagged_with’. It’s my first time using meta_search, so I might be doing something wrong here. 😉 I’ve read somewhere that searchlogic worked in combination with acts_as_taggable_on, but since it doesn’t support Rails 3, I can’t use that.

I hoped somebody here could help me with this problem. Anyone know how to combine acts_as_taggable_on with meta_search? Or maybe know a solution without meta_search? Also, if there’s a better option for acts_as_taggable_on that works with meta_search I’d love to hear that too. 🙂

EDIT:
I got it working without using tagged_with or meta_search. It looked like this:

Post.select("DISTINCT posts.*").joins(:base_tags).where("posts.title LIKE ? OR tags.name = ?", "%"+params[:search]+"%", params[:search])

The query created was ridiculous, so I tried a different route: without acts_as_taggable_on and meta_search. I created a tags table myself and connected it to the posts with has_and_belongs_to_many. I won’t have other tables that need to be connected to the tags, so this will do the trick for me. I created a scope for searching both the tags and title:

scope :search, lambda { |search| select("DISTINCT posts.*").joins(:tags).where("posts.title LIKE ? OR tags.name = ?", "%"+search+"%", search) }

Now I can do the following:

Post.search(params[:search])

It works great and the query is also quite nice. Still, if anyone knows a better way: please tell me. It could also be helpful for the people coming here via Google.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:04:10+00:00Added an answer on May 23, 2026 at 2:04 pm
    Post.metasearch({:title_or_tag_taggings_tag_name_contains => params[:search]})
    

    enjoy

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into
I have some data like this: 1 2 3 4 5 9 2 6
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.