Paths showing up in link_to

我怕爱的太早我们不能终老 提交于 2019-12-11 09:28:16

问题


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.


回答1:


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'%>



回答2:


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?


来源:https://stackoverflow.com/questions/4554915/paths-showing-up-in-link-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!