Rails"入门" guide link_to NameError

时间:2017-12-02 20:57:02

标签: ruby-on-rails link-to

我跟随Rails"入门"指南(在其中创建博客网站),并已达到步骤5.8。此时,您将以表格格式显示目前为止所写的所有文章。每篇文章旁边都有一个指向完整文章的链接:

<h1>Listing articles</h1>

<table>
  <tr>
    <th>Title</th>
    <th>Text</th>
  </tr>

  <% @articles.each do |article| %>
    <tr>
      <td><%= article.title %></td>
      <td><%= article.text %></td>
      <td><%= link_to 'Show', article_path(article) %></td>
    </tr>
  <% end %>
</table>

每当我尝试访问http://localhost:3000/articles时,我在文章#index中得到一个NameError,说:

未定义的局部变量或方法“”显示“&#39;对于#&lt;#:0x00007fb69bb18e98&gt;

articles_controller如下:

class ArticlesController < ApplicationController

    def index
        @articles = Article.all
        end

    def show
        @article = Article.find(params[:id])
        end

    def new
        end

    def create
        @article = Article.new(article_params)

        @article.save
        redirect_to @article
        end

    private
        def article_params
            params.require(:article).permit(:title, :text)
            end

end

指南中给出的任何其他link_to操作似乎都不起作用,我无法弄清楚原因。任何帮助都会受到大力赞赏!

编辑:这是我在终端中获得的内容:

Started GET "/articles" for 127.0.0.1 at 2017-12-02 22:30:21 +0000
   (0.2ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by ArticlesController#index as HTML
  Rendering articles/index.html.erb within layouts/application
  Article Load (0.4ms)  SELECT "articles".* FROM "articles"
  Rendered articles/index.html.erb within layouts/application (322.8ms)
Completed 500 Internal Server Error in 351ms (ActiveRecord: 1.3ms)



ActionView::Template::Error (undefined local variable or method `“Show”' for #<#<Class:0x00007faa22ae61a8>:0x00007faa22acf430>):
    10:         <tr>
    11:         <td><%= article.title %></td>
    12:         <td><%= article.text %></td>
    13:         <td><%= link_to “Show”, article_path(article) %></td>
    14:         </tr>
    15:     <% end %>
    16: </table>

app/views/articles/index.html.erb:13:in `block in _app_views_articles_index_html_erb___2950076423591311193_70184351523660'
app/views/articles/index.html.erb:9:in `_app_views_articles_index_html_erb___2950076423591311193_70184351523660'

0 个答案:

没有答案