Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8859263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:00:57+00:00 2026-06-14T15:00:57+00:00

I have a rails 2.3 application where I defined my routes like this: map.connect

  • 0

I have a rails 2.3 application where I defined my routes like this:

map.connect ':controller/:level1/:level2', :action => 'index'
map.connect ':controller/:level1',         :action => 'index'

I want to make some links like a breadcrumb, depending on the page I’m in. For example, suppose my controller name would be 'contr', if my path is /contr, there would be only one link: '/contr'. If my path would be '/contr/level1/level2', I would like to have 3 links: '/contr', '/contr/level1' and '/contr/level1/level2'.

Here is how I tried:

In my view I detect these levels:

b_titles = []
b_links = []
b_titles << 'Contr'
b_links  << ({:controller=>'contr'})
if !params[:level1].nil?
  b_titles << 'Level 1'
  b_links << ({:controller=>'contr', :level1=> params[:level1]})
  if !params[:level2].nil?
    b_titles << 'Level 2'
    b_links << ({:controller=>'contr', :level1=> params[:level1], :level2=>params[:level2]})
  end
end

After I make these arrays, I test them using function p

p b_links
p b_titles

and in console there are the desired results:

[{:controller=>"contr"}, {:level1=>"level1", :controller=>"contr"}, {:level1=>"level1", :level2=>"level2", :controller=>"contr"}]
["Contr", "Level 1", "Level 2"]

Now I want to make a list of links for the breadcrumb:

<% b_titles.each_with_index do |title, i| %>
    <%= link_to(title, (b_links[i]))  %>
<% end %>

The result I get it this:

<a href="/contr/level1/level2">Contr</a>
<a href="/contr/level1/level2">Level 1</a>
<a href="/contr/level1/level2">Level 2</a>

It makes no sense! Why is there the same link for all the items? The titles are ok, but the links not.

Even if I try to display the links only, with b_links.each do |link| the third link is displayed 3 times. What could be the problem here?

I even tried to make b_links array to contain the strings returned from the url_for method, but without success.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:00:58+00:00Added an answer on June 14, 2026 at 3:00 pm

    If you are at the deepest level, :controller, :level1 and :level2 are all set.

    If you try to make a path with {:controller => "contr"} it will add that to the current environment. This is very easy, and allows us to write something like {:action => 'edit'} which will use the current controller.

    So you will have to adapt your hash to be something like

     [{:controller=>"contr", :level1 => nil, :level2 => nil}, 
      {:level1=>"level1", :controller=>"contr", :level2 => nil}, 
      {:level1=>"level1", :level2=>"level2", :controller=>"contr"}]
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my current rails application I have a bunch of named routes defined to
I have Rails application with mounted Engine. #{main_app}/config/routes.rb mount CommentIt::Engine => /talk, :as =>
I have a Rails application that works with mongodb. I want to deploy it
I have various roles defined by CanCan in my rails application. I recently implemented
I have created an application in Rails, I want to create a puccuentas model:
I have rails application running in linode server .Some guy is continuously spamming (writing
I have a Rails application that accepts file uploads of CSV files. When developing
I have a rails application that about 3 years old, and I'm having a
I have a rails application, running in development mode ( with a sqlite database
I have a Rails application that uses ActiveRecordStore for sessions. I need a PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.