Class: Dorsale::CommentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user_scope

Instance Method Details

#createObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/dorsale/comments_controller.rb', line 3

def create
  @comment = Comment.new(comment_params)
  @comment.author = try(:current_user)

  authorize! :create, @comment

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

  redirect_to_back_url
end

#destroyObject



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

def destroy
  @comment = ::Dorsale::Comment.find params[:id]

  authorize! :delete, @comment

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

  redirect_to_back_url
end

#editObject



18
19
20
21
22
23
24
# File 'app/controllers/dorsale/comments_controller.rb', line 18

def edit
  @comment = ::Dorsale::Comment.find params[:id]

  authorize! :update, @comment

  render layout: false
end

#updateObject



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/dorsale/comments_controller.rb', line 26

def update
  @comment = ::Dorsale::Comment.find params[:id]

  authorize! :update, @comment

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

  redirect_to_back_url
end