On 8/31/05, Joe Van Dyk
<joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi,
>
> I''m struggling to figure out how to properly do the following: I
have
> a menu on the side of the page. The menu links are something like:
>
> "Main", :controller => ''content'', :action
=> ''show'', :name => ''front''
> "Find", :controller => ''communities'',
:action => ''find'', :action => ''map''
> "About", :controller => ''content'', :action
=> ''show'', :name => ''about''
> "Communities", :controller => ''communities''
>
> If I''m on the ''Main'' page, I want that link in
the menu to be colored
> differently. Easy with current_page?.
>
> However, I''m running into problems on how to properly do the
> "Communities" link. The "Communities" index page has
links to various
> communities, that have links like:
> :controller => ''communities'', :action =>
''show'', :id => 2 or
> :controller => ''communities'', :action =>
''people'', :id => 10
>
> The "Community" link in the menu should be colored differently
when
> I''m on any page that''s part of the "Community"
controller (except for
> when I''m on the "find" action -- as there''s
already a link on the menu
> for that page).
>
> Any ideas?
It''s probably not exactly what you''re wanting to do, but on my
previous Rails project I did something like this (see
www.teamworktraining.ca).
I don''t know if I''d recommend doing what I did with that
site... but
basically I set it up so that each page can be configured from a set
of predefined colours. These colours then determine which colour
stylesheet to load up when the page is loaded.
Just shooting out ideas here...
When you''re generating your menu you could do something like (rough):
...snip...
@menu_items.each do |m|
html << "<li"
html << " class=\"#{params[:controller]} selected\""
if
m.controller_name == @params[:controller]
html << ">"
html << m.name
html << "</li>"
end
...snip...
Then just add the appropriate stuff in your stylesheet. If your menu
doesn''t change much, then you could also create an array of hashes
with all sorts of info to help you generate the menu.
Does this help?