Module: Wallaby::Engineable
- Included in:
- ApplicationConcern, ApplicationHelper
- Defined in:
- lib/concerns/wallaby/engineable.rb
Overview
Engine related helper methods to be included for both controller and view.
Instance Method Summary collapse
-
#current_engine ⇒ ActionDispatch::Routing::RoutesProxy
This helper method returns the current Engine routing proxy.
-
#current_engine_name ⇒ String
Find out the Engine routing proxy name for the current request, it comes from either:.
-
#current_engine_route ⇒ ActionDispatch::Journey::Route
Engine route for current request.
-
#script_name ⇒ String
Current engine’s script name.
Instance Method Details
#current_engine ⇒ ActionDispatch::Routing::RoutesProxy
This helper method returns the current Wallaby::Engine routing proxy. For example, if Wallaby is mounted at different paths at the same time:
mount Wallaby::Engine, at: '/admin'
mount Wallaby::Engine, at: '/inner', as: :inner_engine,
defaults: { resources_controller: InnerController }
If ‘/inner` is current request path, it returns `inner_engine` engine proxy.
15 16 17 |
# File 'lib/concerns/wallaby/engineable.rb', line 15 def current_engine @current_engine ||= try current_engine_name end |
#current_engine_name ⇒ String
Find out the Wallaby::Engine routing proxy name for the current request, it comes from either:
-
Current controller’s engine_name
-
Judge from the current request path (which contains the script and path info)
25 26 27 |
# File 'lib/concerns/wallaby/engineable.rb', line 25 def current_engine_name @current_engine_name ||= wallaby_controller.engine_name || EngineNameFinder.execute(request.path) end |
#current_engine_route ⇒ ActionDispatch::Journey::Route
Returns engine route for current request.
30 31 32 33 34 |
# File 'lib/concerns/wallaby/engineable.rb', line 30 def current_engine_route return if current_engine_name.blank? Rails.application.routes.named_routes[current_engine_name] end |
#script_name ⇒ String
This script name prefix is required for Rails #url_for to generate the correct URL.
Returns current engine’s script name.
40 41 42 |
# File 'lib/concerns/wallaby/engineable.rb', line 40 def script_name current_engine_route.try { |route| route.path.spec.to_s } end |