Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 如何在ruby on rails应用程序中创建帖子中的注释字段_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 如何在ruby on rails应用程序中创建帖子中的注释字段

Ruby on rails 4 如何在ruby on rails应用程序中创建帖子中的注释字段,ruby-on-rails-4,Ruby On Rails 4,我想在simply ruby on rails应用程序中添加评论。已解决 我的控制器: class CommentsController < ApplicationController before_filter :authenticate_user! def create binding.pry @adventure = Adventure.find(params[:adventure_id]) @comment = @adve

我想在simply ruby on rails应用程序中添加评论。

已解决

我的控制器:

class CommentsController < ApplicationController
  before_filter :authenticate_user!
    def create
        binding.pry
        @adventure = Adventure.find(params[:adventure_id])
        @comment = @adventure.comments.create(comment_params)

        if @comment.save
            flash[:notice] = "Comment has been created."
            redirect_to @adventure
        else
            flash.now[:danger] = "error"
        end
    end  
      def comment_params
      params.require(:comment).permit(:body)
    end  
end


class Comment < ActiveRecord::Base
    belongs_to :adventure
end
class CommentsController
我是ruby新手,我有一篇帖子,想在帖子中添加评论。你不需要
绑定。pry
那里:)另外,你想使用
评论。新建
而不是
评论。创建