19Aug/090
i18n URL-based breadcrumbs in Rails
in application_helper.rb put this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Generate URL-based Breadcrumbs. # Based on http://rubysnips.com/url-based-breadcrumbs # Modified and adapted for i18n by Claudio Poli (http://www.icoretech.org) def show_breadcrumbs(wrapper = "p", separator = " ยป ") r = [] r < < link_to(I18n.t(:home), "/") url = request.path.split('?') segments = url[0].split('/') segments.shift segments.each_with_index do |segment, i| title = segment.gsub(/-/, ' ').titleize title = I18n.t(title.downcase.to_sym, :default => title) r < < link_to_unless_current(title, "/" + (0..(i)).collect{ |seg| segments[seg] }.join("/")) end content_tag(wrapper, "#{I18n.t(:path)}: " + r.join(separator), :class => "breadcrumbs") end |
Related posts:
- jGrowl on Rails (with i18n)
- Beautify Ruby code in Textmate
- Rails users < membership > groups? Enter Workflow
- Send SMS with Ruby on Rails
- Rails vs. Tarantula
Enjoy this article?
Additional comments powered by BackType