我正在渲染一个标题,其中包含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"更多推荐
发布评论