I have a users_manager engine which has a User model class.
In an other shopping engine, I add some associations in the User model with the code below, in shopping/lib/shopping.rb:
module Shopping
class Engine<Rails::Engine
initializer :shopping_append_user do
UsersManager::User.class_eval do
has_many :products,:class_name=>"Shopping::Product"
has_many :virtues,:class_name=>"Shopping::Virtue"
has_many :containers,:class_name=>"Shopping::Container"
has_many :concerns,:class_name=>"Shopping::Concern"
has_many :remarks,:class_name=>"Shopping::Remark"
has_many :praisings,:class_name=>"Shopping::Praising"
has_one :cart,:class_name=>"Shopping::Cart"
has_one :shop_information,:class_name=>"Shopping::ShopInformation"
has_many :comments,:class_name=>"Shopping::Comment"
has_many :created_orders,:class_name=>"Shopping::Order",:foreign_key=>"creator_id"
has_many :processing_orders,:class_name=>"Shopping::Order",:foreign_key=>"processor_id"
end
end
initializer :shopping_append_file do
Upload::File.class_eval do
has_many :image_uuids,:class_name=>"Shopping::ImageUuid"
end
end
end
def self.table_name_prefix
"shopping_"
end
end
After running rails server, the application works fine. However, after modifying one controller file, I browse the web page and it gives me the following message :
undefined method `products' for #<UsersManager::User:0x00000003022a58>
How does rails reload the file after modifying them? How can I make my engine work right?
My version of rails is 3.2.0.pre from github, Ruby is 1.9.0.
Your initializer isn’t reloaded on every request, this means that your customizations on the
UsersManager::Userclass are lost when it is reloaded.You can do the following instead:
The
config.to_prepareblock is run once in production and before every request in development (source).