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\"}"
The easiest way to do this is to override the retrieval of
due_date.Try this in your model: