Answer the question
In order to leave comments, you need to log in
Using host application helpers in mountable engine views
I have a mountable engine that mounts to the main application.
In the main application, directly in ApplicationHelper
there is a very simple helper edit_link(path)
: you give it a url, it returns the html code of the link.
The engine has a couple of controllers with views (interfaces) in which I want to use this helper.
By default, Rails doesn't let me do this: I've tried using both simple edit_link(path)
and main_app.edit_link(path)
(this works with routes, but not with helpers).
Then I decided to do this:
app/helpers/my_engine/application_helper.rb
module MyEngine
module ApplicationHelper
include ActionView::Helpers::ApplicationHelper
end
end
uninitialized constant ActionView::Helpers::ApplicationHelper
uninitialized constant
the exception anymore. Answer the question
In order to leave comments, you need to log in
In general, it seems to work like this:
lib/my_engine/engine.rb (this is inside the engine)
module MyEngine
class Engine < ::Rails::Engine
isolate_namespace MyEngine
config.to_prepare do
ApplicationController.helper(ActionView::Helpers::ApplicationHelper)
end
end
end
include
killed accordingly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question