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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:41:50+00:00 2026-05-24T11:41:50+00:00

I am using mongoid as my orm, and i call to_json on the result

  • 0

I am using mongoid as my orm, and i call to_json on the result set. The initial implementation works fine, except for the fact that everything is loaded on the fly (as opposed to eager loading)

Simplified schema and code below:

Answer has_many likers 

all_answers=Answer.includes(:likers).all.map{|a| a}
all_answer.to_json(:only=>[:text],:include => {:likers=>{:only=>[:_id,:nickname]}})

I started using this great gem (mongoid_eager_loading), and it works great. However, when i call to_json on the result set

all_answers=Answer.includes(:user, :question,:likers,:comments).all.map{|a| a}
all_answer.to_json(:only=>[:text],:include => {:likers=>{:only=>[:_id,:nickname]}})

I will get this error:

undefined method `serializable_hash' for #<Array:0x00000105b3d020>

This error only happens when I am trying to include an array for example: Answer has_many likers.

I suspect that arrays contained in individual objects does not have the serializable_hash method.

How could I resolve this problem? Any ideas would be greatly appreciated!

  • 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-24T11:41:53+00:00Added an answer on May 24, 2026 at 11:41 am

    Take a look at this post from Miso Engineering:

    http://engineering.gomiso.com/2011/05/16/if-youre-using-to_json-youre-doing-it-wrong/

    The RABL gem (https://github.com/nesquena/rabl) is worth a look if you’re pushing your models out as JSON.

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

Sidebar

Related Questions

I'm using Rails 3 w/ Mongoid, (so no ActiveRecord). Mongoid uses ActiveModel's to_json method,
I'm using pickle 0.3.0 with rails, cucumber and mongoid. I do found that pickle0.3.0
I'm using mongoid , machinist 2 and pickle . But I think, that question
I'm struggling to paginate using mongoid. I'm able to call paginate on my collection
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using JDeveloper , I started developing a set of web pages for a project
Using C#, I need a class called User that has a username, password, active
I recently played with MongoDB in Rails using Mongoid . I like the ability
I have recently been getting my feet wet in MongoDB using Mongoid w/ Rails

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.