轨道路由

发布于 2024-07-12 10:44:41 字数 993 浏览 3 评论 0原文

我在 Rails 上构建了一个新的门户,可以通过以下方式访问:https://xyz.com

是: 1.) 它有 2 个选项卡 – “ShipmentInfo”、“Aging Shipments Dashboard” 均使用

<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.) 当我单击“Aging Shipments Dashboard”选项卡时 – url 应该是 – https://xyz.com/#tab2 但您只能看到 https://xyz.com。 我认为这是因为选项卡的客户端实现。

3.) 单击该选项卡中的“当前摘要”按钮后,我得到了相应的结果,但不是显示设置为“时效货件仪表板”的活动选项卡,而是始终设置为“ShipmentInfo”选项卡。

如何设置 activeTab 将结果获取到已发出请求的相应选项卡? 所有表单请求都使用 GET 方法。

或者有没有一种方法可以根据 activeTab 应设置为“时效货运仪表板”的参数,在 paths.rb 中明确提及?

谢谢, 拉贾。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉城凉梦凉人心 2024-07-19 10:44:42

据我所知,无论 YUI 将 ul 转换为一组选项卡,都可能与 li< 内的 href 无关。 /代码>。 我认为您应该验证生成选项卡的使用语法。

继续,href 链接仅指向当前页面内的锚点。 这意味着客户端(浏览器)不必发送 HTTP 请求来重新获取当前页面。 我不认为现代浏览器会这样做。 我怀疑他们发送了 URL 的锚点部分(# 后面的部分),因为 HTTP 服务器不关心该信息。

这意味着,当用户单击选项卡时,您的 Rails 应用程序永远不会收到通知,并且永远不会获取 # 之后的 URL 部分。 所以你不能在路由表中放置任何关于它的规则。

编辑:我忘了告诉你到底应该发生什么。

  1. YUI(或其他一些 JavaScript 代码)应该附加到 li 的 onClick,根据您的描述,它看起来像一个选项卡。
  2. 当用户单击选项卡时,它会读取 URL,并以某种方式预测要显示的内容标记作为选项卡的内容。 例如,这可能是包含第二个选项卡内容的 div,并且它的 id 可能是 tab2 或其他内容。
  3. 然后,它使当前选项卡的内容不可见。 通常这是使用 CSS display 属性完成的,将其设置为 display: none
  4. 最后,所单击的选项卡的内容变得可见。 这可以使用 display: block 或类似的东西来完成。

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.
云胡 2024-07-19 10:44:42

是的。 您的routes.rb 文件末尾可能已经有这些行:

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

将它们更改为:

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

这样您就可以将两个变量定义为 Rails 应用程序中的不同控制器。 您也可以通过两个操作来执行相同的操作,但这是您的决定。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文