Class: Workarea::Admin::CommentsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #find_sort, #wrap_in_view_model, wrap_in_view_model

Methods included from Publishing

#allow_publishing!, #allow_publishing?, #set_publishing_options

Methods included from Visiting

#most_visited

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/workarea/admin/comments_controller.rb', line 16

def create
  if params[:subscribed_user_ids].present?
    @commentable.add_subscription(params[:subscribed_user_ids])
    @commentable.add_subscription(current_user.id)
  end

  if @comment.save
    flash[:success] = t('workarea.admin.comments.flash_messages.added')
    send_notifications
    redirect_to commentable_comments_path(@commentable.to_global_id)
  else
    @commentable.remove_subscription(params[:subscribed_user_ids])
    flash[:error] = t('workarea.admin.comments.flash_messages.added_error')
    render :index, status: :unprocessable_entity
  end
end

#destroyObject



45
46
47
48
49
# File 'app/controllers/workarea/admin/comments_controller.rb', line 45

def destroy
  @comment.destroy
  flash[:success] = t('workarea.admin.comments.flash_messages.removed')
  redirect_to commentable_comments_path(@commentable.to_global_id)
end

#editObject



33
# File 'app/controllers/workarea/admin/comments_controller.rb', line 33

def edit; end

#indexObject



12
# File 'app/controllers/workarea/admin/comments_controller.rb', line 12

def index; end

#showObject



14
# File 'app/controllers/workarea/admin/comments_controller.rb', line 14

def show; end

#subscribeObject



51
52
53
54
55
56
57
58
# File 'app/controllers/workarea/admin/comments_controller.rb', line 51

def subscribe
  @commentable.add_subscription(current_user.id)
  flash[:success] = t(
    'workarea.admin.comments.flash_messages.comment_subscribed',
    commentable: @commentable.name
  )
  redirect_to commentable_comments_path(@commentable.to_global_id)
end

#unsubscribeObject



60
61
62
63
64
65
66
67
# File 'app/controllers/workarea/admin/comments_controller.rb', line 60

def unsubscribe
  @commentable.remove_subscription(current_user.id)
  flash[:success] = t(
    'workarea.admin.comments.flash_messages.comment_unsubscribed',
    commentable: @commentable.name
  )
  redirect_to commentable_comments_path(@commentable.to_global_id)
end

#updateObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/workarea/admin/comments_controller.rb', line 35

def update
  if @comment.update_attributes(comment_params)
    flash[:success] = t('workarea.admin.comments.flash_messages.saved')
    redirect_to commentable_comments_path(@commentable.to_global_id)
  else
    flash[:error] = t('workarea.admin.comments.flash_messages.saved_error')
    render :edit, status: :unprocessable_entity
  end
end