Dynamic menu ruby on rails and partial

paissepsy

New Member
i'm pretty new to rails and would like some help with implementing a dynamic menu using partials.As of right now, my code is as follows:the menu partial:\[code\].three.columns %ul#nav %li{:class => @active_page=="about" ? "active_page" : ""} %a{:href =http://stackoverflow.com/questions/7294181/>"../pages/about"} About %li{:class => @active_page=="careers" ? "active_page" : ""} %a{:href =http://stackoverflow.com/questions/7294181/>"../pages/careers"} Careers %li{:class => @active_page=="contact" ? "active_page" : ""} %a{:href =http://stackoverflow.com/questions/7294181/>"../pages/contact"} Contact\[/code\]the view:\[code\] html... = render :partial => 'shared/aboutmenu_nav' more html...\[/code\]the pages helper:\[code\]def @active_page(c) controller.action_name == c end\[/code\]Note: \[code\]active_page\[/code\] is the class that I would like to pass to the \[code\]li\[/code\] if the user is on the corresponding page. For example, if the user is on the Contact page, the active_page class would be passed to only the Contact li element.I've tried several solutions including creating multiple CSS versions and passing a class on the \[code\]body\[/code\] corresponding with the page? for example, \[code\]%body{:class => @page_name}\[/code\]and then defining @page_name in the pages_helper as follows:\[code\] def page_name @path.parameterize('_') unless @path.blank? end\[/code\]Neither of these versions seem to work, as the former (@active_page) does not yield any results. Similarly, I was unable to assign a class on the body tag--when I checked the source code, the body tag did not have any classes.I'd appreciate any help on how to implement a dynamic menu using partials. If there is a method I have not tried please feel free to inform me. I sincerely appreciate all of your help, and I'm very thankful for your time! Thank you!Using Kanadada's solution. The page literally displays the following text where the styled menu should appear:\[code\]<li class=""><a href="http://stackoverflow.com/pages/about">About</a></li><li class="active_page"><a href="http://stackoverflow.com/pages/careers">Careers</a></li><li class=""><a href="http://stackoverflow.com/pages/contact">Contact</a></li>\[/code\]This code would be great if it was in the source code; however, the source does not seem to recognize it... instead the source code shows the following code:\[code\] <li class=""><a href=http://stackoverflow.com/questions/7294181/"/pages/about">About</a></li><li class="active_page"><a href="/pages/careers">Careers</a></li><li class=""><a href="/pages/contact">Contact</a></li>\[/code\]I suspect that it might have something to do with the way \[code\]=top_menu\[/code\] is interpreted in HAML?
 
Top