Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to add the following code that I found online as a workaround for a problem with combining MongoDB and Backbone.js in Rails, but I actually don't know Ruby/Rails that well because I'm learning all three at once.

Currently, I've just created a file in lib/ called mongoid.rb with the following content:

module Mongoid
  module BackboneSerialization
    extend ActiveSupport::Concern
    module InstanceMethods
      def serializable_hash(options = nil)
        persisted? ? super.merge('id' => _id) : super
      end
    end
  end
end

Assuming that this code is correct, is there anything else I have to be aware of to make this work. All I'm doing now is adding this code and then starting my server but that doesn't seem to solve the problem. Is there a specific place I need to store it- like lib/mongoid/backbone_serialization/instance_methods? Or do I need to include this in certain files? If so, do I include just Mongoid or submodules?

share|improve this question
1  
Try putting the file in config/initializers and then restart rails –  house9 Jun 30 '13 at 3:46

1 Answer 1

config/environment.rb,

after require File.expand_path('../application', __FILE__)

and before APPNAME::Application.initialize!

add require "mongoid"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.