Created
April 6, 2014 02:24
-
-
Save woshidan/10000742 to your computer and use it in GitHub Desktop.
make-breadcrumb-list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_layer_piecies(url_piecies) | |
layer_piecies = [] | |
url_piecies.each do |url_piece| | |
layer_caption = get_layer_caption(url_piece) | |
if layer_caption == nil | |
category_caption = get_category_caption(url_piece, layer_piecies.last[:url]) | |
layer_piecies.last[:caption] = layer_piecies.last[:caption] + "(#{category_caption})" | |
layer_piecies.last[:url] = layer_piecies.last[:url] + "/#{url_piece}" | |
else | |
url_piece = '/' if url_piece == 'localhost3000' | |
layer_piecies << { caption: layer_caption, url: url_piece } | |
end | |
end | |
layer_piecies | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_layers(layer_piecies) | |
layers = [] | |
layer_url_piecies = [] | |
layer_piecies.each do |layer_piece| | |
layer_url_piecies << layer_piece[:url] | |
end | |
layer_piecies.each_with_index do |layer_piece, i| | |
url = layer_url_piecies[0..i].join('/') | |
url.slice!(0,1) if url != '/' | |
caption = layer_piece[:caption] | |
layers << { caption: caption, url: url } | |
end | |
layers | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% breadcrumbs = get_breadcrumbs %> | |
<% breadcrumbs.each do |breadcrumb| %> | |
<% class_name = 'breadcrumb'%> | |
<% class_name += ' last' if breadcrumbs.last == breadcrumb %> | |
<%= link_to "> " + breadcrumb[:caption], breadcrumb[:url], :class => class_name %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BreadcrumbList::Application.routes.draw do | |
root 'static_pages#home' | |
match "/products", to: 'product_categories#index', via: 'get' | |
match "/products/category/:id", to: 'products#index', via: 'get' | |
match "/products/category/:category_id/product/:id", to: 'products#show', via: 'get' | |
match '/personal', to: 'departments#index', via: 'get' | |
match "/personal/department/:id", to: 'employees#index', via: 'get' | |
match '/personal/department/:department_id/employee/:id', to: 'employees#show', via: 'get' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment