link_to 中显示的路径
我是 Rails 新手,刚刚完成了 Rails for Zombies (railsforzombies.org),并正在尝试构建我的第一个应用程序(博客)。
我搭建了一个基本结构并进行了更改,包括更改路线、添加部分视图和其他视图改进以及安装 Blueprint css 框架。
我遇到的问题是我的所有链接(使用 link_to 创建)最终看起来像这样:
test post(/post/1)
链接的路径在链接本身之后打印。但是,我无法复制带有链接路径的文本。
如果它有帮助,这就是我的routes.rb 的样子:
Blog::Application.routes.draw do |map|
root :to => "Posts#index"
match '/post/:id' => 'Posts#show', :as => 'show'
match 'new' => 'Posts#new', :as => 'new_post'
有帮助吗?
编辑:
我的 link_to 调用如下:
<em><h2 class = "title"><%=link_to post.title, show_path(post.id) %></h2></em>
编辑:
问题可以在 这张图片。
另外,如果我更改为 show_url,则 url 将显示在括号中,而不是路径中。
I am new to rails having just completed rails for zombies (railsforzombies.org) and am trying to build my first app (a blog).
I have scaffolded a basic structure and made changes including changing routes adding partials and other improvements to the view as well as installing the Blueprint css framework.
The problem I'm having is that all of my links (created with link_to) end up looking like this:
test post(/post/1)
Where the path to the link is printed after the link itself. However, I cannot copy the text with the path to the link.
In case it helps this is what my routes.rb looks like:
Blog::Application.routes.draw do |map|
root :to => "Posts#index"
match '/post/:id' => 'Posts#show', :as => 'show'
match 'new' => 'Posts#new', :as => 'new_post'
Any help?
Edit:
my link_to call is as follows:
<em><h2 class = "title"><%=link_to post.title, show_path(post.id) %></h2></em>
Edit:
The problem can be seen in this image.
Also if I change to show_url the url appears in the parenthesis as opposed to the path.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题解决了。
蓝图 CSS 弄乱了我的代码。为了避免这种情况,请确保在包含蓝图 CSS 文件时指定
:media
选项。您的代码应该如下所示:Problem solved.
Blueprint CSS was messing up my code. To avoid this, make sure you specify the
:media
option when including the Blueprint CSS files. Your code should look something like this:这些可能是问题所在,因此请检查:
match '/post/:id' .....
、post
中我认为应该是复数。<%=
和link_to
之间添加空格。link_to
中的show_path(post.id)
更改为show_path(post)
?These are things that may be the problem, so please check:
match '/post/:id' .....
,post
should be plural I believe.<%=
andlink_to
.show_path(post.id)
toshow_path(post)
in thelink_to
?