link_to 中显示的路径

发布于 2024-10-09 17:50:40 字数 885 浏览 0 评论 0原文

我是 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 技术交流群。

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

发布评论

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

评论(2

笑忘罢 2024-10-16 17:50:40

问题解决了。

蓝图 CSS 弄乱了我的代码。为了避免这种情况,请确保在包含蓝图 CSS 文件时指定 :media 选项。您的代码应该如下所示:

<%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
<%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
<%= stylesheet_link_tag 'blueprint/ie'%>

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:

<%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
<%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
<%= stylesheet_link_tag 'blueprint/ie'%>
乖乖哒 2024-10-16 17:50:40

这些可能是问题所在,因此请检查:

  1. match '/post/:id' .....post 中我认为应该是复数。
  2. 不确定,但也可以尝试在 <%=link_to 之间添加空格。
  3. link_to 中的 show_path(post.id) 更改为 show_path(post)

These are things that may be the problem, so please check:

  1. In match '/post/:id' ....., post should be plural I believe.
  2. Not sure, but also try adding a space between <%= and link_to.
  3. Change show_path(post.id) to show_path(post) in the link_to?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文