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

getting const_defined? error when belongs_to :event is used #15

Open
krglobal opened this issue May 28, 2015 · 5 comments
Open

getting const_defined? error when belongs_to :event is used #15

krglobal opened this issue May 28, 2015 · 5 comments

Comments

@krglobal
Copy link

I am upgrading from Rails 2.3 to Rails 3.2 and have many controllers using make_resourceful.

I have a very simple model called TemplateType which I use in my mailings controller.

When I try to get any row from it in my new method, I get:

undefined method `const_defined?' for "event":String

it is failing when trying to run through the controllers parents for some reason... see below.

if I remove the belongs_to :event statement and put in my own code to get the parent event, (my controller is mailings which have an event parent) then the problem clears up. what is make_resourceful trying to do here and how can I get it to not fail? what is different from Rails 2.3 version I wonder.

undefined method `const_defined?' for "event":String

Rails.root: /Users/kurtrobson/rails/ml_32
Application Trace | Framework Trace | Full Trace

activesupport (3.2.18) lib/active_support/dependencies.rb:390:in local_const_defined?' activesupport (3.2.18) lib/active_support/dependencies.rb:508:inblock in load_missing_constant'
activesupport (3.2.18) lib/active_support/dependencies.rb:508:in each' activesupport (3.2.18) lib/active_support/dependencies.rb:508:inany?'
activesupport (3.2.18) lib/active_support/dependencies.rb:508:in load_missing_constant' activesupport (3.2.18) lib/active_support/dependencies.rb:192:inblock in const_missing'
activesupport (3.2.18) lib/active_support/dependencies.rb:190:in each' activesupport (3.2.18) lib/active_support/dependencies.rb:190:inconst_missing'
app/controllers/mailings_controller.rb:51:in block (2 levels) in <class:MailingsController>' make_resourceful (1.0.2) lib/resourceful/default/callbacks.rb:39:ininstance_eval'
make_resourceful (1.0.2) lib/resourceful/default/callbacks.rb:39:in block in scope' make_resourceful (1.0.2) lib/resourceful/default/callbacks.rb:47:incall'
make_resourceful (1.0.2) lib/resourceful/default/callbacks.rb:47:in block in resourceful_fire' make_resourceful (1.0.2) lib/resourceful/default/callbacks.rb:47:ineach'
make_resourceful (1.0.2) lib/resourceful/default/callbacks.rb:47:in resourceful_fire' make_resourceful (1.0.2) lib/resourceful/default/callbacks.rb:12:inbefore'
make_resourceful (1.0.2) lib/resourceful/default/actions.rb:76:in new' actionpack (3.2.18) lib/action_controller/metal/implicit_render.rb:4:insend_action'
actionpack (3.2.18) lib/abstract_controller/base.rb:167:in process_action' actionpack (3.2.18) lib/action_controller/metal/rendering.rb:10:inprocess_action'
actionpack (3.2.18) lib/abstract_controller/callbacks.rb:18:in `block in process_action'

@krglobal
Copy link
Author

here is some debugger output:
[502, 511] in /Users/kurtrobson/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.18/lib/active_support/dependencies.rb
502 require_or_load file_path
503 raise LoadError, "Expected #{file_path} to define #{qualified_name}" unless local_const_defined?(from_mod, const_name)
504 return from_mod.const_get(const_name)
505 elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
506 return mod
=> 507 elsif (parent = from_mod.parent) && parent != from_mod &&
508 ! from_mod.parents.any? { |p| local_const_defined?(p, const_name) }
509 # If our parents do not have a constant named +const_name+ then we are free
510 # to attempt to load upwards. If they do have such a constant, then this
511 # const_missing must be due to from_mod::const_name, which should not
(rdb:1) parent
nil
(rdb:1) from_mod
MailingsController
(rdb:1) from_mod.parent
Object
(rdb:1) from_mod.parents
"event" from_mod.parents.any? { |p| local_const_defined?(p, const_name) }
*** NoMethodError Exception: undefined method `const_defined?' for "event":String

@ghost
Copy link

ghost commented Apr 20, 2016

@krglobal Did you solve this issue? This happened to me too after I upgraded from rails 3.x to 4.x

@krglobal
Copy link
Author

No i did not really solve it but worked around it. by excluding my index
methods from make resourceful and writing my own code to get parent object,
then the problem went away (looking for parent object constant on finder
methods that had nothing to do w parent object).

If you know how to fix root cause I'd love to hear how.
Thx,
Kurt

On Tuesday, April 19, 2016, Dennis Günnewig [email protected]
wrote:

@krglobal https://github.com/krglobal Did you solve this issue? This
happened to me too after I upgraded from rails 3.x to 4.x


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#15 (comment)

Best Regards,
Kurt Robson
Modern Logic International LLC
fax: 815 301 8728

@krglobal
Copy link
Author

now I got another one on an index method that was not even included in the list of make_resourceful methods after making some random code changes that seemingly had nothing to do with it.
eventually I pulled out the belongs_to :member statement and it cleared up.

stay away from belongs_to in your make resourceful usage!

@ghost
Copy link

ghost commented Jun 17, 2016

Thanks for the hint. We started to get rid of the whole gem.

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

No branches or pull requests

1 participant