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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:05:59+00:00 2026-05-19T14:05:59+00:00

When I call to_json on my Factory Girl object, I get a nil.[] error.

  • 0

When I call to_json on my Factory Girl object, I get a nil.[] error.

I’m using DataMapper on Rails 3, and when I call to_json on a real DataMapper object, it works just fine. Any idea why the Factory Girl object is failing?

Factory.define :something do |b|
  b.date_foo { 3.days.ago - 4.hours }
  b.date_bar { 3.days.ago - 4.hours }
  b.somestring '11'
  b.anotherstring 'ASTRINGYAY'
  b.thirdstring 'STRINGG'
  b.fourthstring 'STRING'
  b.otherstring 'thestring'
  b.longerstring 'The string that is longer'
  b.somenumber 3
  b.someothernumber 2
  b.an_id 5593
  b.a_version '1.2.2.2'
  b.a_string '1.2.2.2'
  b.something '1.2.2.2'
  b.code 'SOME CODE'
  b.other_code 'API'
  b.something_id 49
  b.something_version 'OMG'
  b.otherthing 'N/A'
  b.lastthing 'A'
end

Also, I discovered the following:

factory_girl_object.to_json works fine.

[factory_girl_object].to_json fails.

DataMapper apparently uses DataMapper::Collection objects instead of arrays, which handle to_json a bit different for it’s contents than arrays do. I can’t seem to figure out how to create a DataMapper::Collection object to hold my Factory_Girl objects, however.

Thoughts?

  • 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-19T14:06:00+00:00Added an answer on May 19, 2026 at 2:06 pm

    Ha, might as well come back and answer this.

    DataMapper serves objects in a specialized array-like data structure that handles JSON serialization for you. If you try to put DM objects in a regular array, it fails horribly, spawning the errors I mentioned above.

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

Sidebar

Related Questions

I'm using google-http-java-client and GsonFactory as json factory. WHen I get JSON object like
I'm making call to Alfresco Webscripts which return JSON. I do this using GET
I am overriding to_json . When I call to_json on my model I get
I am using mongoid as my orm, and i call to_json on the result
I'm using Jquery (1.3.2) $.post command to trigger an ajax call to a rails
I trying to make my first AJAX with JSON call using jQuery and CodeIgniter.
Im trying to build call to action button on my site using jQuery. I
What method do I call to get the name of a class?
I am trying 'mongo-ruby-driver' for some project. It's working fine except when I call
I'm writing a Rails application, using the 'json' gem, and its behavior where it

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.