小编FBa*_*z51的帖子

无法为CommentsController - Ruby Tutorial找到动作'show'

我试图按照以下指南启动Ruby on Rails.一切顺利,直到我试图销毁(删除评论).

我收到以下错误:找不到CommentsController的动作'show'

我将在下面发布我的代码.

http://guides.rubyonrails.org/getting_started.html

comments_controller.rb

class CommentsController < ApplicationController

  http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy

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

    def destroy
        @article = Article.find(params[:article_id])
        @comment = @article.comments.find(params[:id])
        @comment.destroy
        redirect_to article_path(@article)
    end

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

end
Run Code Online (Sandbox Code Playgroud)

articles_controller

class ArticlesController < ApplicationController

 http_basic_authenticate_with name: "dhh", password: "secret", except: [:index, :show]

    def index
       @articles = Article.all
    end

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

    def new
        @article = Article.new 
    end

    def …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

0
推荐指数
1
解决办法
7211
查看次数

标签 统计

ruby ×1

ruby-on-rails ×1