Class: Wallaby::Engines::CustomAppRoute

Inherits:
BaseRoute
  • Object
show all
Defined in:
lib/routes/wallaby/engines/custom_app_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`.

Instance Attribute Summary

Attributes inherited from BaseRoute

#context, #options, #params

Instance Method Summary collapse

Instance Method Details

#exist?true, false

Returns:

  • (true)

    if the route matches the condition exists

  • (false)

    otherwise



30
31
32
# File 'lib/routes/wallaby/engines/custom_app_route.rb', line 30

def exist?
  route.present?
end

#urlObject



34
35
36
# File 'lib/routes/wallaby/engines/custom_app_route.rb', line 34

def url
  context.url_for(params_for(route), super: true)
end