#的未定义方法“ article_comments_path”是什么意思? article_new_path

时间:2019-12-01 15:53:30

标签: ruby-on-rails ruby ruby-on-rails-4 error-handling

我遇到了错误,我正在遵循Rails指南https://guides.rubyonrails.org/getting_started.html上的ruby 谁能帮我吗 ? 如果您知道答案,则请使用prpoper正确的代码写出文件名。

当我尝试显示文件时显示了这种类型的错误。

show.html

'''

<p>
  <strong>Title:</strong>
  <%= @article.title %>
</p>

<p>
  <strong>Text:</strong>
  <%= @article.text %>
</p>

<h2>Comments</h2>
<% @article.comments.each do |comment| %>
  <p>
    <strong>Commenter:</strong>
    <%= comment.commenter %>
  </p>

  <p>
    <strong>Comment:</strong>
    <%= comment.body %>
  </p>
<% end %>

<h2>Add a comment:</h2>
<%= form_with(model: [ @article, @article.comments.build ], local: true) do |form| %>
  <p>
    <%= form.label :commenter %><br>
    <%= form.text_field :commenter %>
  </p>
  <p>
    <%= form.label :body %><br>
    <%= form.text_area :body %>
  </p>
  <p>
    <%= form.submit %>
  </p>
<% end %>

<%= link_to 'Edit', edit_article_path(@article) %> |
<%= link_to 'Back', articles_path %>
<h1><%= link_to 'new_Article', new_article_path %></h1>

'''

评论控制器

'''

class CommentsController < ApplicationController
  def create
    @article = Article.find(params[:article_id])
    @comment = @article.comments.create(comment_params)
    redirect_to article_path(@article)
  end

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end
end

'''

index.html.erb

'''

<center>

<table border="1pt">
  <tr>
    <th>Title</th>
    <th>Text</th>
    <th colspan="3">id</th>
  </tr>

  <% @articles.each do |article| %>
    <tr>
      <td><%= article.title %></td>
      <td><%= article.text %></td>
      <td><%= article.id %></td>
      <td><%= link_to 'Show', article_path(article) %></td>
      <td><%= link_to 'Edit', edit_article_path(article) %></td>
      <td><%= link_to 'Destroy', article_path(article),
              method: :delete,
              data: { confirm: 'Are you sure?' } %>
      </td>
    </tr>
  <% end %>
</table>
<h1><a href="http://localhost:3000/articles/new">new article</a>
</h1>
</center>

'''

article_controller

'''

class ArticlesController < ApplicationController
    def index
      @articles = Article.all
    end

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

    def new
        @article =Article.new
    end

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

    def create
      @article = Article.new(article_params)

      if @article.save
        flash[:notice] = "Article was submitted succsefully"
        redirect_to(@article) 
       else
        render 'new'
      end
    end

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

        if @article.update(article_params)
            redirect_to @article
        else
            render 'edit'
        end
    end

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

        redirect_to articles_path
    end

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

'''

我遇到了错误,我正在遵循Rails指南https://guides.rubyonrails.org/getting_started.html上的ruby 谁能帮我吗 ? 如果您知道答案,则请使用prpoper正确的代码写出文件名。

当我尝试显示文件时显示了这种类型的错误。

0 个答案:

没有答案