Forum: Ruby on Rails Creating a Navigation menu...

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E38fd7ebdb2c3e6816808b8da4eaf117?d=identicon&s=25 Differenthink (Guest)
on 2007-07-11 16:52
(Received via mailing list)
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.
3203ed0e608d3bfae1e31282e629ffa2?d=identicon&s=25 Peter Fitzgibbons (Guest)
on 2007-07-11 19:27
(Received via mailing list)
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 Fitzgibbons
------------------------------
iPhone -- "IT"-ness.
href=
http://www.macdailynews.com/index.php/weblog/comme...
------------------------------
E38fd7ebdb2c3e6816808b8da4eaf117?d=identicon&s=25 Differenthink (Guest)
on 2007-07-11 23:07
(Received via mailing list)
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 Fitzgibbons" <peter.fitzgibb...@gmail.com>
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (au5lander)
on 2007-07-12 01:26
(Received via mailing list)
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]
3203ed0e608d3bfae1e31282e629ffa2?d=identicon&s=25 Peter Fitzgibbons (Guest)
on 2007-07-12 04:39
(Received via mailing list)
Good way, Chris.  I wasn't thinking routes when I first answered.

Tell us how it goes, Guillaume.

Peter Fitzgibbons
------------------------------
iPhone -- "IT"-ness.
href=
http://www.macdailynews.com/index.php/weblog/comme...
------------------------------
E38fd7ebdb2c3e6816808b8da4eaf117?d=identicon&s=25 Differenthink (Guest)
on 2007-07-12 18:36
(Received via mailing list)
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 ? "
Db7238007950074e9e73b76a81910406?d=identicon&s=25 tonypm (Guest)
on 2007-07-14 10:53
(Received via mailing list)
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
E38fd7ebdb2c3e6816808b8da4eaf117?d=identicon&s=25 Differenthink (Guest)
on 2007-07-15 23:28
(Received via mailing list)
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.
Db7238007950074e9e73b76a81910406?d=identicon&s=25 tonypm (Guest)
on 2007-07-17 22:01
(Received via mailing list)
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

On Jul 15, 10:27 pm, Differenthink <guillaume.mont...@gmail.com>
This topic is locked and can not be replied to.