Class: Wallaby::Engines::EngineRoute

Inherits:
BaseRoute
  • Object
show all
Defined in:
lib/routes/wallaby/engines/engine_route.rb

Overview

The general route of Wallaby::Engine looks like as follow:

/admin/order::items

Therefore, to override this route, dev needs to define a resources as below before mounting Wallaby::Engine:

namespace :admin do
  # NOTE: in order for the route to work properly,
  # the colon before words need to be escaped in the path option
  resources :items, path: 'order:\:item', module: :order
end
wallaby_mount at: '/admin'

So to find out if any route has been overriden with current request, e.g. ‘/admin/order::items/1/edit`, we will look into the following conditions:

  • begins with ‘/admin`

  • same action as the given action

  • default controller exists (as ResourcesRouter does not define static controller)

Then we use this route’s params and pass it to the origin ‘url_for`.

Constant Summary collapse

ACTION_TO_URL_HELPER_MAP =

A constant to map actions to its corresponding path helper methods defined in Wallaby::Engine‘s routes.

Wallaby::ERRORS.each_with_object(ActiveSupport::HashWithIndifferentAccess.new) do |error, map|
  map[error] = :"#{error}_path"
end.merge(
  home: :root_path,
  # for resourceful actions
  index: :resources_path,
  new: :new_resource_path,
  show: :resource_path,
  edit: :edit_resource_path
).freeze

Instance Attribute Summary

Attributes inherited from BaseRoute

#context, #options, #params

Instance Method Summary collapse

Instance Method Details

#urlObject



43
44
45
46
47
48
# File 'lib/routes/wallaby/engines/engine_route.rb', line 43

def url
  # NOTE: require to use `url_helper` here.
  # otherwise, {Engine} will raise **ActionController::UrlGenerationError**.
  engine_params = params_for(route)
  Engine.routes.url_helpers.try(engine_action_url_helper, engine_params)
end