Rails models cannot be accessed through components
Reported by carter (at carterparks) | December 22nd, 2008 @ 06:17 PM | in 0.8.4
I am able to access a Rails model through the Dialplan but upon accessing through a component ahn spits out the following stack trace:
ERROR agi: #<NameError: wrong constant name #<Adhearsion>
ERROR agi: /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:352:in `const_defined?'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:352:in `constantize'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `each'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `constantize'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/module/introspection.rb:31:in `parent'
/opt/local/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:88:in `const_missing'
/Users/carter/git/mytym_adhearsion/components/notifier/notifier.rb:15:in `start'
/Users/carter/git/mytym_adhearsion/components/notifier/notifier.rb:3:in `notifier'
/Users/carter/git/mytym_adhearsion/dialplan.rb:2:in `load'
/Users/carter/git/adhearsion/lib/adhearsion/voip/dial_plan.rb:50:in `instance_eval'
/Users/carter/git/adhearsion/lib/adhearsion/voip/dial_plan.rb:50:in `run'
/Users/carter/git/adhearsion/lib/adhearsion/voip/dial_plan.rb:105:in `handle'
/Users/carter/git/adhearsion/lib/adhearsion/voip/dial_plan.rb:81:in `handle'
/Users/carter/git/adhearsion/lib/adhearsion/voip/asterisk/agi_server.rb:23:in `serve'
/opt/local/lib/ruby/1.8/gserver.rb:211:in `start'
/opt/local/lib/ruby/1.8/gserver.rb:208:in `initialize'
/opt/local/lib/ruby/1.8/gserver.rb:208:in `new'
/opt/local/lib/ruby/1.8/gserver.rb:208:in `start'
/opt/local/lib/ruby/1.8/gserver.rb:198:in `initialize'
/opt/local/lib/ruby/1.8/gserver.rb:198:in `new'
/opt/local/lib/ruby/1.8/gserver.rb:198:in `start'
/Users/carter/git/adhearsion/lib/adhearsion/voip/asterisk/agi_server.rb:66:in `start'
/Users/carter/git/adhearsion/lib/adhearsion/initializer/asterisk.rb:56:in `join_server_thread_after_initialized'
/Users/carter/git/adhearsion/lib/theatre.rb:66:in `call'
/Users/carter/git/adhearsion/lib/theatre.rb:66:in `trigger_immediately'
/Users/carter/git/adhearsion/lib/theatre.rb:63:in `map'
/Users/carter/git/adhearsion/lib/theatre.rb:63:in `trigger_immediately'
/Users/carter/git/adhearsion/lib/adhearsion/events_support.rb:47:in `trigger_immediately'
/Users/carter/git/adhearsion/lib/adhearsion/initializer.rb:349:in `trigger_after_initialized_hooks'
/Users/carter/git/adhearsion/lib/adhearsion/initializer.rb:143:in `start'
/Users/carter/git/adhearsion/lib/adhearsion/initializer.rb:92:in `start'
/Users/carter/git/adhearsion/lib/adhearsion/cli.rb:129:in `start'
/Users/carter/git/adhearsion/lib/adhearsion/cli.rb:19:in `send'
/Users/carter/git/adhearsion/lib/adhearsion/cli.rb:19:in `execute!'
../adhearsion/bin/ahn:28
Using Adhearsion trunk (http://github.com/jicksta/adhear... and Rails Gem 2.2.2
Comments and changes to this ticket
-
Jay Phillips December 23rd, 2008 @ 09:17 PM
- State changed from new to open
-
Jay Phillips December 25th, 2008 @ 01:57 AM
I can't reproduce this issue. I created a new Adhearsion app, new Rails app, wired them together, created a simple component, and called into the app.
Are you using the gem from Github? It could be that this was a bug at some distant time in the past and Github's .gem hasn't caught up to the latest master. We had issues with that in the past...
Check out the .zip which contains my sample app. Try running it and post your results here.
Marking this ticket "invalid" for now. Will gladly reopen it if it's truly an issue.
-
Jay Phillips December 25th, 2008 @ 02:04 AM
- State changed from open to invalid
-
carter (at carterparks) December 30th, 2008 @ 02:01 PM
Your sample app worked just fine, but if I create a class within the component (like the SimonGame component), that class cannot access any Rails classes. Attached is a revision to your ar-components app that illustrates this.
-
jsgoecke March 17th, 2009 @ 08:41 PM
I am experiencing a similar issue. I have a class 'ActiveCallSessions' that I instantiate at startup (initialization do in my component) that accesses an Active Record model from Rails. The 'ActiveCallSessions' object is used by various elements of the component system. If I first access the 'ActiveCallSessions' class from the dialplan (in methods_for :dialplan in my component) it has no problem accessing that AR model both from the dialplan or events in my component.
But, if, for example, I never answer the phone and the events subsystem tries to access the 'ActiveCallSessions' object that attempts to access the AR model then I get this error:
ERROR update_user: Caught NameError: wrong constant name #<Adhearsion
/usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:352:in `const_defined?' /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:352:in `constantize' /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `each' /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/inflector.rb:351:in `constantize' /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/string/inflections.rb:162:in `constantize' /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/core_ext/module/introspection.rb:31:in `parent' /usr/lib/ruby/gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:88:in `const_missing'
So it would appear if the dialplan does not play with the object first, that object does not have the AR models in scope.
-
jsgoecke March 17th, 2009 @ 09:22 PM
I moved my method from events into global in the component and the problem persists. This leads me to believe it has something to do with AGI being active versus only AMI.
-
Robert October 14th, 2009 @ 03:10 PM
Wanted to add a note to this ticket. I had the same problem as described by the OP and jsgoecke and I spent hours searching internet with no explanation/answer to the problem to be found. Anyway, what finally got it to work for me was changing the path for the config param 'models' in .ahnrc to point to the directory where my AR models were:
models: models/*.rb <-- default value; not working
models: gui/app/models/*.rb <-- changed value; working :-)
The somewhat hidden problem is that referencing AR models by enabling rails in config/startup.rb works fine when referencing in dial plan, but apparently needs this additional config change when referencing in a component.
HTH
-
Ben Klang March 5th, 2010 @ 04:23 PM
I'm writing to mention that I'm having the same problem as the OP.
I'm using Adhearsion 0.8.3 and ActiveRecord 2.3.5.While trying to access an AR class within an component, I get a similar error message:
ERROR agi: #<NameError: wrong constant name #
ERROR agi: /var/ruby/1.8/gem_home/gems/activesupport-2.3.5/lib/active_support/inflector.rb:361:inconst_defined?'
This is a brand new installation of Adhearsion and a brand new ahn application. I'll be happy to post my module if that is helpful.
-
Ben Klang March 5th, 2010 @ 04:26 PM
A couple of other data points to share:
In reference to jsgoecke's comment, I am using both AGI and AMI.
In reference to Robert's comment, I trie dchanging my .ahnrc but it not change my error message noticeably.
Rails is not enabled in my Adhearsion config, but database is.
-
Ben Klang March 14th, 2010 @ 04:30 PM
I may have a solution to this.
Today I found that if I use the ActiveRecord class in dialplan before calling it within the component, everything works fine. However, if I call info ActiveRecord class in the component without first using it in the dialplan, I get the exception stated above. This leads me to believe it may be a problem in the order of initialization.
To remedy this, I found the lines in Adhearsion::Initializer#start and noticed that the components were initialized before the modules (such as ActiveRecord) were loaded. After reversing the two lines, ActiveRecord within components works fine for me.
Example patch below:
diff --git a/lib/adhearsion/initializer.rb b/lib/adhearsion/initializer.rb
index ef67617..be1e940 100644
--- a/lib/adhearsion/initializer.rb +++ b/lib/adhearsion/initializer.rb @@ -130,8 +130,8 @@ module Adhearsionbootstrap_rc initialize_log_file load_all_init_files
- init_components_subsystem init_modules
- init_components_subsystem init_events_subsystem load_components init_events_file
-
Ben Klang March 14th, 2010 @ 04:31 PM
Whoops, forgot to mark the patch as code:
diff --git a/lib/adhearsion/initializer.rb b/lib/adhearsion/initializer.rb index ef67617..be1e940 100644 --- a/lib/adhearsion/initializer.rb +++ b/lib/adhearsion/initializer.rb @@ -130,8 +130,8 @@ module Adhearsion bootstrap_rc initialize_log_file load_all_init_files - init_components_subsystem init_modules + init_components_subsystem init_events_subsystem load_components init_events_file
-
Ben Klang June 22nd, 2010 @ 01:14 PM
- Tag changed from component, rails to component
- State changed from invalid to resolved
- Assigned user changed from Jay Phillips to Ben Klang
This issue has been fixed. The commits will appear in the official repository shortly and be included in the next release.
-
Ben Klang June 22nd, 2010 @ 01:16 PM
- Milestone set to 0.8.4
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป