Sha256: 10cc745018563c0fce98acee2294aaf050df0fe77ab726755f04a6a52e9efa7d

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

class CommentsController < ApplicationController
  before_action :set_comment, only: [:destroy]

  # POST /comments
  def create
    @comment = Comment.new(comment_params)
    @comment.user = current_user

    if @comment.save
      @comment.notify_later :users, key: 'comment.create.later'
      # @comment.notify       :users, key: 'comment.create.later', notify_later: true
      @comment.notify_now   :users, key: 'comment.create.now'
      # @comment.notify       :users, key: 'comment.create.now'
      redirect_to @comment.article, notice: 'Comment was successfully created.'
    else
      redirect_to @comment.article
    end
  end

  # DELETE /comments/1
  def destroy
    article = @comment.article
    @comment.destroy
    redirect_to article, notice: 'Comment was successfully destroyed.'
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_comment
      @comment = Comment.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def comment_params
      params.require(:comment).permit(:article_id, :body)
    end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activity_notification-1.7.1 spec/rails_app/app/controllers/comments_controller.rb
activity_notification-1.7.0 spec/rails_app/app/controllers/comments_controller.rb