Sha256: 02ea01fc6e601735e589e984b9678b366bd28df7200fad1633a9682df2968297

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

class User::CommentsController < User::BaseController
  before_action :set_finish
  before_action :require_collaborator_access

  def new
    @comment = Comment.new
    render "shared/comments/form"
  end

  def create
    @comment = @finish.comments.build(comment_params)
    @comment.user = current_user

    if @comment.save
      redirect_to [@project, @finish],
        notice: "Comment successfully added."
    else
      render "shared/comments/form"
    end
  end

  def edit
    set_comment
    render "shared/comments/form"
  end

  def update
    set_comment

    if @comment.user != current_user
      flash[:error] = "You are not permitted to edit this comment."
      redirect_to [@project, @finish]
      return
    end

    if @comment.update_attributes(comment_params)
      redirect_to [@project, @finish],
        notice: "Comment successfully updated."
    else
      render "shared/comments/form"
    end
  end

  private

  def comment_params
    params.require(:comment).permit(:body)
  end

  def set_project
    @project ||= current_user.projects.find params[:project_id]
  end

  def set_finish
    @finish ||= set_project.finishes.find params[:finish_id]
  end

  def set_comment
    @comment ||= set_finish.comments.find params[:id]
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
self_systeem-0.1.0 test/dummy_app/app/controllers/user/comments_controller.rb