Paths showing up in link_to

2019-08-02 07:37发布

问题:

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?