Forum: Ruby on Rails Navigation

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.
E25296bf52723dc37bc462271eb02d2d?d=identicon&s=25 jpfeifer (Guest)
on 2005-12-07 08:20
(Received via mailing list)
Greetings,

I appreciate the help from here as I seem to be asking the noob
questions a lot, but what is a good way to deal with navigation pulled
from a database?

I have this in my view:

<% @nav_buttons.each do |nav_button| %>
        <li><a href="#" class="nav"><%=h nav_button.name %></a></li>
<% end %>

this in my controller

def index
        shownav
    end
    def shownav
        @nav_buttons = NavButton.find(:all)
    end

and I want to make it so that one of the class="nav" list items has an
id="active" decided by a default variable for the homepage, which I will
assign a value to as another section is clicked.  I realize this is
probably pretty micky mouse for most on this list, but I promise once I
am up to speed on rails a bit more I'll help the new guys around here
:-)

Cheers,

Jason
22580f640e491f0920a192610d1df393?d=identicon&s=25 atomgiant (Guest)
on 2005-12-07 18:28
(Received via mailing list)
Hi Jason,

I'll give this a shot:

Let's say you store the active button name in a variable called
@active_button_name.

In your view, you could just add this into the href link:

  <%= 'id = "active"' if nav_button.name == @active_button_name %>

So, this would change your view code to:

<% @nav_buttons.each do |nav_button| %>
  <li><a href="#" class="nav" <%= 'id = "active"' if nav_button.name
== @active_button_name %>><%=h nav_button.name %></a></li>
<% end %>


Tom
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (seancribbs)
on 2009-06-04 15:45
(Received via mailing list)
Rafael,

Try adding slashes on the ends of your URLs; and yes, <r:navigation> has
pretty primitive matching of URLs.

Sean
6bed9a8f9c823d56f34b67ef6f64db98?d=identicon&s=25 Rafael Souza (Guest)
on 2009-06-04 16:26
(Received via mailing list)
I fixed it modifying the core radiant.
There is a simple way to contribute?
09477c358c5897d44121a248326e16d7?d=identicon&s=25 Jim Gay (Guest)
on 2009-06-04 16:32
(Received via mailing list)
Fork. Branch. Spec. Code. Pull Request.
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (seancribbs)
on 2009-06-04 16:38
(Received via mailing list)
Someone should put that on a sign or t-shirt!

Sean
This topic is locked and can not be replied to.