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

  • SEARCH
  • Home
  • 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 7667589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:08:37+00:00 2026-05-31T15:08:37+00:00

Using Rails 3.2.2 and Ruby 1.9.2. I have a rails mountable engine EngineA that

  • 0

Using Rails 3.2.2 and Ruby 1.9.2.

I have a rails mountable engine EngineA that declares a User class inheriting form ActiveRecord::Base. I have another engine EngineB that wants to inject functionality into EngineA::User. Right now what I have done is shown below:

Method 1:

#EngineA app/models/engine_a/user.rb
module EngineA
  class User < ActiveRecord::Base
    has_attached_file :avatar
    has_many :somethings
  end
end

#EngineB lib/engine_b/user.rb
module EngineB
  module User
    def self.extended obj
      obj.class_eval do
        has_many :something_elses
      end
    end
  end
end

EngineA::User.extend EngineB::User

This gives me an uninitialized constant EngineA::User error. Even when I require that specific file I run into the problem of EngineA needing paperclip so that has_attached_file is understood. That road ended when I realized I would have to know and require the dependencies for EngineA inside EngineB.

Method 2:

I used the same code as before except I removed the last line EngineA::User.extend EngineB::User from the EngineB user.rb file. I then moved that call to an initializer inside EngineB.

#EngineB config/initializers/my_mixin.rb
EngineA::User.extend EngineB::User

This worked perfectly!!! Except in development mode when I would change code and the models would refresh. The only thing that was refreshed was the EngineA::User and not the mixin that I had put as an initializer. So once I changed code, I lost all of my extended functionality.

I’m not even positive this is the most ‘efficient’ way to do this… any help would be greatly appreciated. Thanks in advance.

  • 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-31T15:08:39+00:00Added an answer on May 31, 2026 at 3:08 pm

    According to the configuration documentation, you can use an ActionDispatch callback to load items. These callbacks will run when at every request if cache_classes is set to false, like in development mode.

    Inside of your EngineB.rb file, you might try something like this:

    if Rails.env.development?
        ActionDispatch::Callbacks.to_prepare do
            load "#{File.expand_path(File.dirname(__FILE__))}/../config/initializers/my_mixin.rb"
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Ruby on Rails page that loads another page using jquery. I
I have a Ruby application (not using Rails) that use my own Ruby gems.
I am using ruby on rails with a MySQL backend. I have a table
I have created a blog application using Ruby on Rails which includes the ability
I have built a very simple blog application using Ruby on Rails. New to
I have been using ActiveResource in my Ruby on Rails applications for some time,
we have a mixed development environment using ASP.NET MVC and Ruby on Rails. We
says if i develop a Ruby on Rails application using Rails 2.3.2, will that
I'm new to Ruby on Rails, looking at using it for an app that
(Using Rails 3.1.3) I have an app that manages products. I import the products

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.