Rails 3.2 Engine Layouts

后端 未结 1 366
萌比男神i
萌比男神i 2020-12-09 10:19

I\'m struggling to understand how Rails 3.2 applies layouts when using mountable engines.

Scenario: I\'m building an engine which itself has a dashboard view and an

相关标签:
1条回答
  • 2020-12-09 11:05

    I've debugged the problem and actually it's not a bug in Engines. The problem is caused by the way rails dependencies are loaded.

    This code will behave differently in 2 scenarios that you're showing:

    module Enginedemo
      class DashboardController < ApplicationController
      end
    end
    

    If ApplicationController is already loaded, rails will assume that we just want to use it and you will actually not inherit from Enginedemo::ApplicationController but from ApplicationController. In the other scenario, when you first load engine's controller, ApplicationController is not loaded yet, so Rails does the right thing.

    Thankfully this problem occurs only in development environment as in production controllers are loaded when application is booting.

    I'm not sure if this is something that can be easily fixed in rails dependencies, I will take a look at it.

    For now, please explicitly require application controller:

    require 'enginedemo/application_controller'
    
    module Enginedemo
      class DashboardController < ApplicationController
      end
    end
    
    0 讨论(0)
提交回复
热议问题