I have a Rails 3 app that defines some classes like normal. I am trying to figure out how to reopen one of those classes within a plugin (generated by "rails generate plugin ..."), and have both of the files (the file in the app itself and the file in the plugin) automatically reload on every request in development mode.
A simple example would be:
# root/lib/person.rb
class Person
Core = 1
end
# root/vendor/plugins/plugin1/lib/person.rb
class Person
Plugin = 2
end
# root/app/views/home/index.html.erb
<%= Person::Core %> ... <%= Person::Plugin %>
When that view is rendered, I get an error that Bike::Plugin is uninitialized. I have added both root/lib and root/vendor/plugins/plugin1/lib to my autoload_paths (ideally the plugin would add that in its init.rb or somewhere similar, but one thing at a time).
How do I go about this? autoload_at kind of looks like it might help, if I can tell it to autoload the Person class from both locations explicitly, but I have not had any luck (I am completely new to it though, so I may be passing the wrong arguments, etc). In the end I want to do this with classes defined in the standard places (models in particular) and not just lib as well.