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

  • SEARCH
  • Home
  • 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 7176645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:33:09+00:00 2026-05-28T16:33:09+00:00

My Rails 3 app has a UserAction object that I use to store information

  • 0

My Rails 3 app has a UserAction object that I use to store information about actions taken on my site.

I’m trying to filter the results so that I only get ones where the data attribute is set to a specific value, but for some reason it always returns an empty array.

Here’s an example from the console showing the first record, a query that returns it based on the ‘action’ attribute, and the one that’s not working for the ‘data’ attribute:

> UserAction.first
UserAction Load (39.6ms)  SELECT "user_actions".* FROM "user_actions" LIMIT 1
=> #<UserAction id: 1, source: "127.0.0.1", action: "Failed login attempt", data: "admin", created_at: "2012-01-12 11:26:38", updated_at: "2012-01-12 11:26:38"> 

> UserAction.where('action = ?', "Failed login attempt")
UserAction Load (1.2ms)  SELECT "user_actions".* FROM "user_actions" WHERE (action = 'Failed login attempt')
 => [#<UserAction id: 1, source: "127.0.0.1", action: "Failed login attempt", data: "admin", created_at: "2012-01-12 11:26:38", updated_at: "2012-01-12 11:26:38">] 

> UserAction.where('data = ?', "admin")
UserAction Load (96.5ms)  SELECT "user_actions".* FROM "user_actions" WHERE (data = 'admin')
=> [] 

Why does Rails return an empty array for the second query when there’s clearly a record where the data equals “admin”? I should note that I’m currently upgrading the app from Rails 2.3.5, so it might be something new introduced in Rails 3 (I am using Rails 3.1.2). Also, I’ve started using Postgresql in development instead of Sqlite, which I was using before.

Thanks in advance.

  • 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-28T16:33:10+00:00Added an answer on May 28, 2026 at 4:33 pm

    I figured out the answer (kind of):

    The data parameter was serialized and for some reason when Rails 3’s ActiveRecord deserializes a string, it doesn’t equal the string you search for with your query.

    I removed the serialize and it worked.

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

Sidebar

Related Questions

We have a Rails app that instantiates a SWF object 16 times (it has
I'm building a rails app that has a page with a jstree object on
I have a rails app that has picked up a bit of traction, but
I have a rails app that has asynchronous processing, and I'm having trouble getting
I have a rails app that has a private component and a public component.
I'm building a Rails app that has Etsy.com style functionality. In other words, it's
I'm working on a rails app that has a whole bunch of before filters
I have an app running Rails 2.3.5 that has a JSON API for much
Say that a Rails app has a Car and an Order model. The Car
We have a Rails app that has some pages that are available to all

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.