Thanks for the reply, Maurício.  Out of curiosity, what is the reason 
that this does not work the way that I thought it would.  I am planning 
to delve into the Rails class loader code tonight, but, if you can shed 
any light on this I'd much appreciated it.

> Place this code into an initializer file (under the initializers
> folder) or place it under the "lib" folder and do an explicit require.

I've actually had similar problems trying to use initializers with 
plugins in the past.  Specifically, I've tried to use an initializer to 
define application specific values for constants used by my plugin. For 
example:

# config/initializers/my_class.rb
class Jason::MyClass
  MY_CONSTANT = "the application's value for this constant"
end

Rails, in this case, appears to load the class definition from the 
initializer and stops there, i.e., it never loads the rest of the class 
definition from the plugin. So, calling a method defined in the plugin's 
version of the class like a_method, would also result in the 
NoMethodError...

$ script/console
>> Jason::MyClass.new.a_method
NoMethodError: undefined method `a_method' for
#<Jason::MyClass:0x408b444>

> Jason::MyClass.class_eval do
>   def another_method
>     # do whatever you want to do here.
>   end
> end

I actually tried this approach.  I placed this exact code in my 
app/models/my_class.rb version of the class and it results in the same 
NoMethodError. However, if I place it in environment.rb it works like a 
charm!  :-/

It seems to me that once the class has been defined either by the plugin 
or by an initializer (it appears the initializer is loaded, then the 
plugin, then the model), Rails will not allow any modifications to it. 
Any additional thoughts?

Jason
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to