Topic: Script/console with a plugin

So I am trying to use acts-as-taggable-on (http://github.com/mbleigh/acts-as-taggable-on/) and am having some issues. One problem is that I can't use the gem at all. I install it and configure it but when I try and run the server it complains that I don't have the gem. So I decided to install it as a plugin. It works fine in the context of the Rails app in a browser.

If I try and use script/console and check out the model that I used the acts_as_taggable_on on it freaks out and says the method does not exist. Why would a plugin not load in a console session?

Rails 2.3.4
gem 1.3.5
ruby 1.8.7

Re: Script/console with a plugin

Can you provide a stack trace?

Re: Script/console with a plugin

NoMethodError: undefined method `acts_as_taggable_on' for #<Class:0x2412d30>
  from /Library/Ruby/Gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:1959:in `method_missing'
  from /Users/ryan/Sites/testing/app/models/bookmark.rb:2
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:380:in `load_without_new_constant_marking'
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:380:in `load_file'
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:521:in `new_constants_in'
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:379:in `load_file'
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:259:in `require_or_load'
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:425:in `load_missing_constant'
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in `const_missing'
  from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in `const_missing'
  from (irb):1

It's like it doesn't see the plugiin so the method doesn't exist. I guess the console isn't loading the dependency correctly but I have no idea why it isn't.

Last edited by Ryan S (2010-01-26 16:32:02)

Re: Script/console with a plugin

Well, let's see -- put a puts statement in the plugin's init.rb file, so we can see that it is being loaded.

Re: Script/console with a plugin

No output appears when I just put a puts statement in the plugin's init.rb file. Do I have to do a require in the console session? That seems weak.

Re: Script/console with a plugin

Do you have another plugin installed, that you can put a puts in its init.rb?  We need to rule on whether it is the plugin or your installation.

And no, you shouldn't have to require the plugin.

Last edited by pullmonkey (2010-01-26 17:54:31)

Re: Script/console with a plugin

hrm it does appear that none of the other plugins are loading in the console. I guess the reason I didn't run in to it is because I don't reference them directly in the console. The one I need to access works on a model which I am trying to fiddle around with.

Of course this all assumes that just doing a

p 'here'

in the init.rb file will show up when the console loads if the plugins are loaded.

Re: Script/console with a plugin

I put p "here" at the top of RAILS_ROOT/vendor/plugins/add_nested_fields/init.rb and this is what I see ....

pullmonkey:~/Projects/.../trunk$ ./script/console 
Loading development environment (Rails 2.3.4)
"here"
>> 

Re: Script/console with a plugin

Not getting any of that. So know I need to figure out why the console isn't loading the plugins in console but the server is. This isn't a huge deal. I am just trying to broaden my understanding of what is going on. I really appreciate your help.