Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Simple Nested Pathing For Basic Routes

DZone's Guide to

Simple Nested Pathing For Basic Routes

·
Free Resource
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

end


Now 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
  "/"
end


If 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
end


I'm working on a more robust method to capture all of the possible routes.
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}