mongoid-rspec icon indicating copy to clipboard operation
mongoid-rspec copied to clipboard

undefined method `accepts_nested_attributes_for'

Open webdev36 opened this issue 7 years ago • 2 comments

I'm using mongoid version is 5.1.x with this gem but just got this error in the rspec test. How can I solve this issue? undefined method accepts_nested_attributes_for' for Order:Class`

webdev36 avatar Sep 25 '18 16:09 webdev36

You most likely forgot to include Mongoid::Document in your model ? Are you using Rails, what's your version ?

Startouf avatar Sep 25 '18 23:09 Startouf

Hi @Startouf , Thanks for your kind response. I've already added the Mongoid::Document to my model, but just got error when use this method

['Customer', 'Order'].each do |model|
      origin_class = Module.const_get("::#{model}", false)
      if origin_class
        require "ccavenue/ext/#{model.downcase.gsub(/\W/,'_')}_model"
        extension = Module.const_get("Ccavenue::Ext::#{model}Model")
        origin_class.send(:include, extension)
      end
    end

occurs error when calling this method origin_class = Module.const_get("::#{model}", false)

webdev36 avatar Sep 28 '18 07:09 webdev36