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 users < membership > groups? Enter Workflow
  4. Send SMS with Ruby on Rails
  5. Rails vs. Tarantula

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Additional comments powered by BackType