我想在rails应用程序中简单地在ruby中添加评论。
答案 0 :(得分:0)
解决。
我的控制器:
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