Class: Dorsale::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/dorsale/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/dorsale/comments_controller.rb', line 20

def create
  @comment ||= scope.new(comment_params_for_create)
  @commentable = @comment.commentable

  authorize @comment, :create?

  if @comment.save
    flash[:success] = t("messages.comments.create_ok")
  else
    flash[:danger] = t("messages.comments.create_error")
  end

  render_or_redirect
end

#destroyObject



51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/dorsale/comments_controller.rb', line 51

def destroy
  authorize @comment, :delete?

  if @comment.destroy
    flash[:notice] = t("messages.comments.delete_ok")
  else
    flash[:alert] = t("messages.comments.delete_error")
  end

  render_or_redirect
end

#editObject



35
36
37
# File 'app/controllers/dorsale/comments_controller.rb', line 35

def edit
  authorize @comment, :update?
end

#indexObject



10
11
12
13
14
15
16
17
18
# File 'app/controllers/dorsale/comments_controller.rb', line 10

def index
  @comment     = scope.new(comment_params_for_create)
  @commentable = @comment.commentable
  @comments    = scope
    .where(commentable: @commentable)
    .preload(:commentable, :author)

  authorize @commentable, :read?
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/dorsale/comments_controller.rb', line 39

def update
  authorize @comment, :update?

  if @comment.update(comment_params_for_update)
    flash[:notice] = t("messages.comments.update_ok")
  else
    flash[:alert] = t("messages.comments.update_error")
  end

  render_or_redirect
end