如何在rails app上的ruby中发表评论字段

时间:2015-08-12 16:36:35

标签: ruby-on-rails-4

我想在rails应用程序中简单地在ruby中添加评论。

1 个答案:

答案 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