Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: wrong constant name #192

Open
c0mrade opened this issue May 4, 2017 · 5 comments
Open

NameError: wrong constant name #192

c0mrade opened this issue May 4, 2017 · 5 comments
Labels

Comments

@c0mrade
Copy link

c0mrade commented May 4, 2017

I ll describe everything I've done just so I m not missing anything obvious, here is what I've done so far :

  1. Created a class :
# app/models/history_tracker.rb
class HistoryTracker
  include Mongoid::History::Tracker
end
  1. Added an initializer :
# config/mongoid_history.rb
Mongoid::History.tracker_class_name = :history_tracker
  1. Added tracking to my model
class Agreement
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::History::Trackable
  include Mongoid::Attributes::Dynamic

  field :licencing_fee, type: Integer
  field :q1_dollars, type: Integer
  field :q2_dollars, type: Integer
  field :q3_dollars, type: Integer
  field :q4_dollars, type: Integer

  track_history   :on => [:licencing_fee, :q2_dollars, :q2_dollars, :q3_dollars, :q4_dollars],     # track title and body fields only, default is :all
                  :modifier_field => :modifier, 
                  :modifier_field_inverse_of => :nil, 
                  :version_field => :version,        
                  :track_create   =>  true,          
                  :track_update   =>  true,        
                  :track_destroy  =>  true   
end
  1. When performing save! on my model I set the modifier:
user = ....
agreement = Agreement.new
agreement.modifier = user
agreement.licencing_fee = 500
agreement.save!
  1. Then save! method produces this error :
NameError: wrong constant name 
from /Users/nedstark/workspace/agreement-guide/vendor/bundle/gems/activesupport-5.0.1/lib/active_support/inflector/methods.rb:261:in `const_get'

What am I doing wrong here?

@dblock
Copy link
Collaborator

dblock commented May 5, 2017

What's the stack here? Check that the model is actually loaded (just stick a puts inside history_tracker.rb).

@dblock dblock added the bug? label May 5, 2017
@h8rry
Copy link

h8rry commented Aug 1, 2017

@dblock I encountered the same problem. It seems that, by default, the model HistoryTracker wasn't loaded. I had to add the mongoid_history.rb in the initializer (which the documentation states is optional).

@dblock
Copy link
Collaborator

dblock commented Aug 3, 2017

Interesting, this probably is a bug, would appreciate a PR to fix it. Maybe we can even have a spec for this?

@sumandroid
Copy link

sumandroid commented May 6, 2018

Definitely the tracking history problem I encountered this problem and after disabling the tracking temporarily, the error was gone. @h8rry is right!!!

@ArmandoAssuncao
Copy link

This problem occurence because only include the module Mongoid::History::Tracker not call the your block included.
So how tracker_class_name is nil, the line raises error NameError: wrong constant name

klass = history_trackable_options[:tracker_class_name] || Mongoid::History.tracker_class_name
klass.is_a?(Class) ? klass : klass.to_s.camelize.constantize

some possible solutions are:

  • creates the initializer file.
  • or activate eager_load config.eager_load = true in file config/enviroments/development.rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants