Simple Nested Pathing For Basic Routes
Join the DZone community and get the full member experience.Join For Free
If you are using simple resources and actions you can use the following snippet to make simple path links. such as Home > Items > New First add this to the application helper.
module ApplicationHelper def path_links link_to("Home", controller.parent_path) + " > " + link_to(controller.controller_name, :controller => controller.controller_path, :action => :index) + " > " + link_to(controller.action_name, :controller => controller.controller_path, :action => controller.action_name) end endNow in your layout simply call path_links. You will get something like the following Home > customers > new Now add the new method to the application_controller
def parent_path "/" endIf you desire to use namespaces like /system/users/new then simply override the parent_path method in the base controller for that namespace.
class SystemController < ApplicationController def parent_path "/system" end endI'm working on a more robust method to capture all of the possible routes.
Opinions expressed by DZone contributors are their own.