Creating a Navigation menu...

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.

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?

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... :confused:

Is there a way to bypass that problem ?

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/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/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]

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

Tell us how it goes, Guillaume.

Peter Fitzgibbons

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... :confused: Is there a way to bypass that problem ? "

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

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.

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="<ul id='menuButtons'>\n <li>"   x+=link_to("Data File", {:action=>'get_amazon_orders_file', :controller=>'amazon_orders'} )   x+="</li>\n <li>"   x+=link_to("Import Customers", {:action=>'import_customers', :controller=>'amazon_orders'} )   x+="</li>\n <li>"   x+=link_to("List", {:action=>'list',:controller=>'customers'} )   x+="</li>\n</ul>"   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