iCoreTech Research Labs Just a placeholder

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:

  1. jGrowl on Rails (with i18n)
  2. Beautify Ruby code in Textmate
  3. Rails vs. Tarantula
  4. Send SMS with Ruby on Rails

About kain

My name is Claudio Poli, I'm an Italian web developer interested in employing new technologies in my projects and contributing back. Check out my latest project: AudioBox.fm. You can follow me on Twitter, GitHub, WWR, and last.fm.
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Additional comments powered by BackType