# Creating a Navigation menu

**URL:** <https://www.ruby-forum.com/t/creating-a-navigation-menu/109122>\
**Category:** Rails\
**Created:** [July 11, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122 "2007-07-11T16:52:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 11, 2007, 4:52pm UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/1 "2007-07-11T16:52:09Z")

</div>

Hi,

I m trying to create a navigation menu as the one at the top of digg  
website…  
My navigation menu is composed of Menu, and Submenu… menu and  
submenu are form query to the DB…

So right now, in my application layout, i ve put my Menu items …  
I would like when i click on it, that the submenu show below the  
menu… but my problem is that right now to do that i m using an  
action to perform the the submenu show…

The big problem with this solution is that when i navigate to an other  
action, the submenu disapear… :(…  
and i would like it to stay until i open an other menu…

So i guess that i should n t use an action to make the sub menu  
appear… how would you to that ?  
(i don t want to use ajax)

Thanks a lot,

Guillaume.

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 11, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/2 "2007-07-11T19:27:07Z")

</div>

Diggs menus are not from a database (so it seems).  
As large as the menu/submenu set is, it points to distinct interest  
areas.

Given that assumption, You’d do well to follow their lead : menu system  
is  
static to defined ‘areas’, dynamic content is provided in lists on  
content\_for\_layout.

Anyone happen to know the “actual” technology behind digg menus?

## – Peter F.

## iPhone – “IT”-ness. href= [Apple’s iPhone could become iconic ‘It Object’ - MacDailyNews](http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object)

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 11, 2007, 11:07pm UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/3 "2007-07-11T23:07:40Z")

</div>

i said digg menu because it s how i want mine, in the sense of menu  
and submenu…  
My problem is that i m not able to show submenu without using an  
action, and using an action cause the problem that when i call an  
other action, the submenu disapear… 😕

Is there a way to bypass that problem ?

On Jul 11, 7:26 pm, “Peter F.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 12, 2007, 1:26am UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/4 "2007-07-12T01:26:59Z")

</div>

did my sample not help you? as i said, there is no action required  
specifically for menu display. it works, for the most part, the way  
digg does

[http://www.digg.com/view/technology](http://www.digg.com/view/technology)

[http://www.digg.com/hardware](http://www.digg.com/hardware)

the first url above lists the stories that fall under the main topic  
of technology

the second url lists the stories that fall under the topic technology,  
subtopic hardware

in my example to you

[http://www.diggclone.com/topics/technology](http://www.diggclone.com/topics/technology)

[http://www.diggclone.com/topics/technology/hardware](http://www.diggclone.com/topics/technology/hardware)

these would do the same thing as the digg versions.

so the routes for my example are such

map.main\_topic /stories/:main\_topic, :controller =\> ‘story’, :action =\>  
‘topic’

map.sub\_topic /stories/:main\_topic/:sub\_topic, :controller =\> ‘story’,  
:action =\> ‘topic’

the topic action of the story controller would be used to lookup all  
the stories of the particular topic and subtopic using  
params[:main\_topic] and params[:sub\_topic]

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 12, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/5 "2007-07-12T18:36:44Z")

</div>

Well kind of hard to understand for me, but i will, i ll keep you  
posted…

Anyway i would like to know if there is a simple answer to this  
question :

"My problem is that i m not able to show submenu without using an  
action, and using an action cause the problem that when i call an  
other action, the submenu disapear… 😕  
Is there a way to bypass that problem ? "

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 14, 2007, 10:53am UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/6 "2007-07-14T10:53:44Z")

</div>

Hi,

I think what you are asking is how can you keep the correct level of  
menus displayed after re-rendering a page following an action. My  
approach to this, (and if there are other possibilities I would  
welcome them) is to hold the current command/menu level in the  
session, and then have application helpers that build the buttons  
based on that session info. The helper can then be called from the  
layout, so that you don’t have to think about menu levels for each  
action. You only need to change the session menu setting when a menu  
selection needs to change the sub menu.

I hope that makes sense or perhaps I am being too simplistic for what  
you require.

tonypm

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 12, 2007, 4:39am UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/7 "2007-07-12T04:39:14Z")

</div>

Good way, Chris. I wasn’t thinking routes when I first answered.

Tell us how it goes, Guillaume.

## Peter F.

## iPhone – “IT”-ness. href= [Apple’s iPhone could become iconic ‘It Object’ - MacDailyNews](http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object)

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 17, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/8 "2007-07-17T22:01:25Z")

</div>

Ok,

The helper builds a string with the menu tags and then this is  
jincluded into the layout like any other tag helper.

Here is some of my code (I like to use the += to concat strings, but  
others may comment that it is not the best way0

In application\_helper.rb

def customer\_buttons  
x=“

\n - ”  
x+=link\_to(“Data File”,  
{:action=\>‘get\_amazon\_orders\_file’, :controller=\>‘amazon\_orders’} )  
x+=“
\n - ”  
x+=link\_to(“Import Customers”,  
{:action=\>‘import\_customers’, :controller=\>‘amazon\_orders’} )  
x+=“
\n - ”  
x+=link\_to(“List”, {:action=\>‘list’,:controller=\>‘customers’} )  
x+=“
\n
”  
return x  
end

def context\_buttons(command)  
if session[‘user’] # application buttons only once logged in  
case command  
when ‘admin’  
admin\_buttons  
when ‘customer’  
customer\_buttons  
end  
end  
end

In the layout:

\<%= context\_buttons(session[:command])%\>

The only other part is to store the command into the session in the  
appropriate actions. I do this from actions called from a set of main  
buttons that select the main command areas.

hth  
Tonypm

On Jul 15, 10:27 pm, Differenthink [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![differenthink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/6bbea6/32.png) [@differenthink](https://www.ruby-forum.com/u/differenthink)\
**Post date:** [July 15, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/creating-a-navigation-menu/109122/9 "2007-07-15T23:28:24Z")

</div>

Well it seems very clear and very helpful… your understood my  
problem !!!  
I think i ve an idea of how to do it, it s just the part where i  
should call the helper from the layout,  
i would like to know how to call an helper form a layout ?

(i’ve never used helper via layout)…

Thanks a lot for everything…

Guillaume.
