Topic: [SOLVED]Writing conditional HTML options for link_to(tabbed interface)

Hi all,

I am trying to implement tabbed navigation in my application. What i need is very simple. I need to set the id to "current" when a particular link_to(tab) is selected. The css takes care of the rest. My tabs are basically just link_to(s). i am able to set it n see the effect. But i need to set it only if that link is clicked, or if that controller is called. I have seen the tabbed navigation plugin in the widgets and the code seems a little too much for my need.
I have been trying to write a condition into the erb tags but its not working. Hope someone has a solution. Here's what i have

<div class="menu">
            <ul>
                <li>
                    <%= link_to 'Dashboard', :controller => :dashboard, :action => :show%>
                </li>
                <li>
                    <%= link_to 'Companies', companies_path(), :id=>"current"%>#setting id like this with a condition is what i need
                </li>
                       </ul>
</div>

Also, passing the :id key and value seems to work only with RESTful routes. Does not work with controller/action specifications. Any thoughts on that?

Last edited by yourstruly_vinay (2008-10-11 05:08:55)

Re: [SOLVED]Writing conditional HTML options for link_to(tabbed interface)

Did not think i would run into trouble with this. Ive tried many combinations

<%= link_to 'Companies', companies_path(), :id=>"current" unless controller.controller_name != 'Companies' %>
<%= link_to 'Companies', companies_path(), if controller.controller_name == 'Companies' :id=>"current" end%>
<%= link_to 'Companies', companies_path(), if controller.controller_name != 'Companies' :id=>"current" %>
<%= link_to 'Companies', companies_path(), if current_page?(:controller=> 'Companies') :id=>"current" end%>

All throwing me syntax errors. Is there a way to do this inline or do i have to write a helper method for this? Anyone?

Last edited by yourstruly_vinay (2008-10-07 04:55:10)

Re: [SOLVED]Writing conditional HTML options for link_to(tabbed interface)

Solution -> http://groups.google.co.in/group/rubyon … 44dd41ff83