Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6941735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:55:26+00:00 2026-05-27T12:55:26+00:00

I have a users_manager engine which has a User model class. In an other

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:55:27+00:00Added an answer on May 27, 2026 at 12:55 pm

    Your initializer isn’t reloaded on every request, this means that your customizations on the UsersManager::User class are lost when it is reloaded.

    You can do the following instead:

    module Shopping
      class Engine < Rails::Engine
        config.to_prepare do
          Shopping.customize_user
          Shopping.customize_file
        end
      end
    
      def self.customize_user
         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
    
      def self.customize_file
        Upload::File.class_eval do
          has_many :image_uuids,:class_name=>"Shopping::ImageUuid"
        end
      end
    
      def self.table_name_prefix
        "shopping_"
      end
    end
    

    The config.to_prepare block is run once in production and before every request in development (source).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a some code in an engine style plugin which includes some models.
I have a page which basically allows an admin user to create manager user
I have an Application (an appointment manager) which lets the user create usercontrols in
I have a little engine (defined as public class ScreenManager : DrawableGameComponent ) to
I have an ASP.NET site which I'd like to add page-level comments to without
I have generated a resource named fax in the users_manager engine: apple@apple1:~/jiuhe/users_manager$ rails g
I have users table. There are three other tables: developers, managers, testers. All of
I am writing a project on Google App Engine, within it I have a
We have a series of products with built in web servers each of which
I have somewhat of a problem. We have a centralized interface engine that will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.