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 203299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:21:59+00:00 2026-05-11T17:21:59+00:00

I have this block of code: users = Array.new users << User.find(:all, :conditions =>

  • 0

I have this block of code:

users = Array.new
users << User.find(:all, :conditions => ["email like ?", "%foo%"])
users << User.find(:all, :conditions => ["name like ?", "%bar%"])
users.flatten!
users.uniq!
puts users.to_json :include => [:licenses]

When I run it using script/console, it returns exactly what you would think it should, a JSON representation of the Array of users that I found, flattened, and uniquified. But running that same line of code as part of a search_for_users method, I get this error

TypeError in ControllerName#search_for_users
wrong argument type Hash (expected Data)

and the line referenced is the line with the .to_json call.

It’s baffling me because the code is verbatim the same. The only difference is that when I’m running it in the console, I’m entering the conditions manually, but in my method, I’m pulling the query from params[:query]. But, I just tried hardcoding the queries and got the same result, so I don’t think that is the problem. If I remove the :include, I don’t see the error, but I also don’t get the data I want.

Anyone have any idea what the issue might be?

  • 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-11T17:21:59+00:00Added an answer on May 11, 2026 at 5:21 pm

    There are a few plugins and gems that can cause .to_json to fail if included in your controller. I believe that the Twitter gem is one of them (ran into a problem with this awhile back).

    Do you have “include [anything]” or “require [anything]” in this controller?

    If not, I’d suggest temporarily removing any plugins you’re using to troubleshoot, etc.

    Finally, what happens if you replace that entire controller action with simply:
    %w(1 2 3 4 5).to_json

    That should help you pin down what is failing.

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

Sidebar

Ask A Question

Stats

  • Questions 98k
  • Answers 98k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer 1) char16_t and char32_t will be distinct new types, so… May 11, 2026 at 7:36 pm
  • Editorial Team
    Editorial Team added an answer EMACS uses an external program to do the compression/uncompression. All… May 11, 2026 at 7:36 pm
  • Editorial Team
    Editorial Team added an answer SQL> create table parent_tbl(col1 char(20) primary key); Table created. SQL>… May 11, 2026 at 7:36 pm

Related Questions

I'm working on a roguelike style cellphone game that operates on a grid. Attacks/Items
I'm doing some Wave file handling and have them read from disk into an
So I've just started digging into Objective-C, Cocoa, and iPhone development. I've ran into
I'm in the design stage for an app which will utilize a REST web
Hey there, I've got a block of HTML that I'm going to be using

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.