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 8056939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:52:07+00:00 2026-06-05T08:52:07+00:00

Background I am creating a application that is made up of a core and

  • 0

Background

I am creating a application that is made up of a core and several modules. The modules are rails engines, and provide the actual functionality as the core itself only acts as a host.
The engines are hosted from /lib and mounted at their respective paths.

coreApp
└──lib
   ├── module1
   ├── module2
   └── etc

The modules are then mounted like this

mount Module1::Engine => "/module1", :as => "module1"
mount Module2::Engine => "/module2", :as => "module2"

The core is also responsible for handeling the session, although the login itself is done by a module.

Problem

I have yet to find a great way of sharing the core application layout with the engines. As of now, this is how I make the layout available to the engines:

coreApp
└── app
    └── views
        └── layouts
            ├── application.html.erb
            └── core.html.erb

The file core.html.erb only contains

<%= render :template => 'layouts/application' %>

Is is then included in each module like this

module Module1
  class ApplicationController < ActionController::Base
    layout "core"
  end
end

Although it isn’t particularly elegant, it works fine, and the content of the module is rendered where the yield statement in the application layout.

The problems are as follows:

1. Module specific stylesheets are not included in the header

I need a way to include the stylesheets of the active module.

2. The header needs access to information about the logged in user

The header contains information about the logged in user, like

Logged in as <%= @user[:realname] %>

This comes from the cores home_controller

def index
  @user = User.find_by_id(session[:user])
end

But when I try to access the module, I get the following error

NoMethodError in Module1/home#index

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]

Obviously referring to @user.

Question

How can this be solved in as elegantly and DRY as possible without too much tampering on the engine side?

I have Googled this a lot but can’t really get my head around how to solve it. It might be total lack of insight in how rails works, so there is a good chance this question doesn’t even make sense for someone that knows rails well.

Please comment if anything is unclear or ambiguous, and I’ll try to elaborate.

  • 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-06-05T08:52:09+00:00Added an answer on June 5, 2026 at 8:52 am

    I have successfully used layouts of my parent application in my engines. Firstly, based on Section 4.3.2 of the Rails Guides (Engines), in order to access the parent applications ApplicationController’s variables (like session, as you’re using above), you need to replace the engine’s application_controller.rb from this that you currently have:

    module Module1
      class ApplicationController < ActionController::Base
        layout "core"
      end
    end
    

    to this:

    class Module1::ApplicationController < ::ApplicationController
    end
    

    This will inherit the parent application’s ApplicationController, along with all it’s variables.

    Secondly, you’ll need to delete the file app/views/layouts/application.html.erb from your engine views, as it will not be needed since you’re using the parent application’s one.

    Now when you render a view of Module1 from the parent application, the layout of the parent application will be used, and all the session[] variables will be evaluated correctly.

    Do not forget to add the words “main_app.” before each link in your layouts, otherwise it will try and look for the paths in the engine instead of the parent application. For example, if the layout in the parent application includes a link to some_path (that is a view in the parent application), when showing a view in the engine that uses this layout will try and look for some_path in the Engine instead of the parent application. You will need to change the link to main_app.some_path for it to work.

    Hope this helps.

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

Sidebar

Related Questions

Background: I am creating a REST api, that will require users to use only
I'm creating a backgrounded cocoa application. The only thing that it's missing is the
Background: I work in a suite of ASP.NET applications that have several different modules.
First, the background: I am creating a Flex application with a component that displays
I am creating an desktop application that runs at background and while clicking the
I have an application that runs in the background only (by specifying LSBackgroundOnly in
I am creating one application in that i want to give background effect like
Background: I'm creating a toolkit of custom components that extend current components functionality, layout,
I'm creating an application Appcelerator Titanium which as an external background image (wood with
Background: I'm creating a dashboard as a project and I have a query that

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.