Skip to content

Instantly share code, notes, and snippets.

@eveevans
Created February 16, 2012 18:31
Show Gist options
  • Save eveevans/1846895 to your computer and use it in GitHub Desktop.
Save eveevans/1846895 to your computer and use it in GitHub Desktop.
Rails Breadcrumb
<%= make_breadcrumb(yield :breadcrumb) %>
module BreadcrumbHelper
def add_breadcrumb(nombre,direccion = "#")
content_for(:breadcrumb) { link_to(nombre,direccion) }
content_for(:breadcrumb) {"///"} #separador para split
end
def make_breadcrumb(extencion)
breadcrumb = [link_to('Inicio', root_path)]
breadcrumb << begin
extencion.empty? ?
[link_to(controller.controller_name.humanize, url_for(controller: controller.controller_name) )]
: extencion.split("///")
end
breadcrumb << [link_to(es(controller.action_name), "#", :class =>'no_link' )] if controller.action_name != 'index'
breadcrumb.join(' &raquo; ').html_safe
end
def es(cadena)
case cadena
when "edit" then "editar"
when "show" then "mostrar"
when "new" then "nuevo"
end
end
end
<% add_breadcrumb "Docentes", docentes_path %>
<% add_breadcrumb "Docente", docente_path(params[:docente_id]) %>
<% add_breadcrumb "Experiencias", docente_path(params[:docente_id], anchor: 'experiencias') %>
# Sin necesidad de Helper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment