Ruby on rails 4 如何在ruby on rails应用程序中创建帖子中的注释字段
我想在simply 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
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
那里:)另外,你想使用评论。新建而不是评论。创建