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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:16:42+00:00 2026-05-25T18:16:42+00:00

hi i am new to ruby on rails and using mongoid with rails. when

  • 0

hi i am new to ruby on rails and using mongoid with rails.
when i try to convert an mongoid object into json the attributes with nil values are skipped.

ruby-1.9.2-p180 :019 >@task
 => #<Task _id: 4e707635c7b4700ce3000004, _type: "Task", created_at: 2011-09-14     09:39:01 UTC, updated_at: 2011-09-14 09:39:01 UTC, due_date: nil, is_completed: false, assignee_id: nil, description: "hi remind this ", user_id: BSON::ObjectId('4e4d1aeac7b4700c6e000096'), item_id: BSON::ObjectId('4e53585fc7b4701082000002')>  

@task.to_json(:only=>[:due_date])
=> "{}" 

is there any way to get like "{\"due_date\":\"null\"}"

  • 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-25T18:16:43+00:00Added an answer on May 25, 2026 at 6:16 pm

    The easiest way to do this is to override the retrieval of due_date.

    Try this in your model:

    def due_date
      real_value = self[:due_date]
      return real_value unless real_value.nil?
      return "null"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have built a very simple blog application using Ruby on Rails. New to
I am new to Ruby on Rails. I am using Netbeans IDE. While importing
I am using cucumber and RSpec for my new ruby on rails application and
I am using cucumber to write features for a new ruby on rails application.
New to rails/ruby (using rails 3 and ruby 1.9.2), and am trying to get
I'm new to Ruby on Rails, looking at using it for an app that
I'm fairly new to ruby (and am using Rails) and was wondering whether the
I'm relatively new to Ruby on Rails. I'm using a particular gem my_gem in
OK, so I'm really new to Ruby on Rails. I'm using InstantRails, if that
I'm using Ruby on Rails 3.1 with mongoid and trying to set up som

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.