views:

406

answers:

2
+1  Q: 

Rails Routing

Hi All,

     I have built a new portal on Rails which can be accessed as say: https://xyz.com

The problem with this is: 1.) It has 2 tabs – “ShipmentInfo” , “Aging Shipments Dashboard” both implemented using

<li> tags and YUI library’s tabview.
    <ul class="yui-nav">
        <li id="tab1" class="selected"><a href="#tab1">Shipment Info</a></li>
        <li id="tab2"><a href="#tab2">Aging Shipments Dashboard</a></li>
    </ul>

2.) When I click on “Aging Shipments Dashboard” tab – url should be – https://xyz.com/#tab2 but you get to see only https://xyz.com . I presume it because of client side implementation of Tabs.

3.) After I click on “Current Summary” button in that tab, I get the corresponding results but instead of showing me the active Tab set to “Aging Shipments Dashboard” it is always set to “ShipmentInfo” tab.

How can I set the activeTab on getting the results to corresponding Tab from which request has been placed ? All form requests use GET method.

Or is there a way wherein I can explicitly mention in routes.rb, basing on the params that the activeTab should be set to “Aging Shipments Dashboard”?

Thanks, Raja.

+1  A: 

As far as I can tell, whatever the YUI does to transform that ul into a set of tab probably has nothing to do with the hrefs inside the li. I think you should verify the usage syntax for producing your tabs.

Moving on, the href links only point to anchors within the current page. Which means the client (browser) doesn't have to send an HTTP request to re-get the current page. I don't think that modern browsers ever do. I doubt they send the anchor part of the URL (the part after the #) since the HTTP server doesn't care about that information.

What this amounts to, is that your rails application is never notified about when the user clicks on a tab, and never gets the part of the URL after #. So you can't put any rules about it in the routing table.

EDIT: I forgot to tell you what really should happen.

  1. The YUI (or some other javascript code) should attach to the onClick of the li, which looks like a tab, from your description.
  2. When the user clicks on a tab, it reads the URL, and in some way divines what content-tag to display as the tab's content. For example, this could be a div that contains the 2nd tabs content, and it could have an id of tab2 or something.
  3. It then makes the current tab's content invisible. Usually the is done using the CSS display property, setting it to display: none.
  4. Finally, the content for the tab that was clicked on is made visible. Which would be done using display: block or something simliar.
scraimer
A: 

Yes. You probably already have these lines at the end of your routes.rb file:

map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format'

Change them to:

map.connect '#:controller' map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format'

This way you can define the two variables as different controllers within the rails app. You could probably do the same thing as two actions too, but that's your call.