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; endend
class BarEngine::ApplicationController < ActionController::Base
def welcome; endend
class BarEngine::SessionsController < FooEngine::SessionsControllerend
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
endend
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.