无论页面如何,都链接到控制器的索引(link

编程入门 行业动态 更新时间:2024-10-18 22:29:40
无论页面如何,都链接到控制器的索引(link_to a controller's index regardless of the page)

我正在渲染一个标题,其中包含application文件中各种控制器的链接

link_to使用的路径似乎是相对于当前页面,它只是指向当前URL减去正斜杠的一个实例。 如果你的水平比第一级更深,那么这不起作用。

例如,单击posts控制器的链接可以在posts #index上工作,但是在posts/1可以指向posts/posts

路线与此有关吗?

I'm rendering a header with links to various controllers in the application file

The path that link_to uses seems to be relative to the current page, and it just directs to the current URL minus one instance of a forward slash. This doesn't work if you're any level deeper than first one.

For instance, clicking a link to the posts controller works while you're on posts#index, but being on posts/1 directs you to posts/posts

Have routes got anything to do with this?

最满意答案

我刚刚通过在目标之前添加正斜杠来纠正此问题。

link_to "posts", "/posts"

I just rectified this problem by adding a forward slash before the destination.

link_to "posts", "/posts"

更多推荐

本文发布于:2023-04-29 01:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1334514.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   索引   页面   链接   link

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!