I have an engine related rails issue.
I have two engines, of which one is mounted.
- FooEngine
- BarEngine (mounted at: “/bar”) I have three controllers:
class FooEngine::SessionsController < BarEngine::ApplicationController
def new; end
end
class BarEngine::ApplicationController < ActionController::Base
def welcome; end
end
class BarEngine::SessionsController < FooEngine::SessionsController
end
In my BarEngine routes file:
BarEngine::Engine.routes.draw do
root to: "application#welcome"
resources :sessions, only: [:new]
end
For some reason, the view context is not what I expect it to be when I go to “/bar/sessions/new”. I would expect to have access to “root_path” for instance, but I do not. I need to use “bar.root_path”. E.g.
class BarEngine::SessionsController < FooEngine::SessionsController
def new
view_context.root_path # does not work
view_context.bar.root_path # works
end
end
This is surprising to me because BarEngine::SessionsController inherits from FooEngine::SessionsController which inherits from BarEngine::ApplicationController. It seems I’m somehow in the wrong scope inside BarEngine::SessionsController.