Class: CamaleonCms::Admin::CommentsController

Inherits:
CamaleonCms::AdminController show all
Defined in:
app/controllers/camaleon_cms/admin/comments_controller.rb

Instance Method Summary collapse

Methods inherited from CamaleonCms::AdminController

#ajax, #cama_get_i18n_frontend, #dashboard, #search

Instance Method Details

#answerObject

render a form to register a new comment



25
26
27
28
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 25

def answer
  @answer = @comment.children.new
  render 'form_answer', layout: false
end

#createObject



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

def create
  @post.comments.create(cama_comments_get_common_data.merge({ post_id: @post.id,
                                                              content: params[:comment][:content] }))
  flash[:notice] = t('camaleon_cms.admin.comments.message.responses')
  redirect_to action: :index
end

#destroyObject



69
70
71
72
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 69

def destroy
  flash[:notice] = t('camaleon_cms.admin.comments.message.destroy') if @comment.destroy
  redirect_to action: :index
end

#editObject



20
21
22
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 20

def edit
  render 'form', layout: false
end

#indexObject

list of post comments for current post



16
17
18
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 16

def index
  @comments = @post.comments.main.paginate(page: params[:page], per_page: current_site.admin_per_page)
end

#listObject



9
10
11
12
13
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 9

def list
  @posts = current_site.posts.no_trash.joins(:comments).select("#{CamaleonCms::Post.table_name}.*, #{CamaleonCms::PostComment.table_name}.post_id").uniq.paginate(
    page: params[:page], per_page: current_site.admin_per_page
  )
end

#newObject



57
58
59
60
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 57

def new
  @comment = @post.comments.new
  render 'form', layout: false
end

#save_answerObject

save a new anwer for this comment



31
32
33
34
35
36
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 31

def save_answer
  @comment.children.create(cama_comments_get_common_data.merge({ post_id: @post.id,
                                                                 content: params[:comment][:content] }))
  flash[:notice] = t('camaleon_cms.admin.comments.message.responses')
  redirect_to action: :index
end

#toggle_statusObject

toggle status of a comment



39
40
41
42
43
44
45
46
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 39

def toggle_status
  _s = { a: 'approved', s: 'spam', p: 'pending' }
  k = _s[params[:s].to_sym]
  @comment.update(approved: k)
  flash[:notice] =
    "#{t('camaleon_cms.admin.comments.message.change_status')} #{t("camaleon_cms.admin.comments.message.#{k}")}"
  redirect_to action: :index
end

#updateObject



48
49
50
51
52
53
54
55
# File 'app/controllers/camaleon_cms/admin/comments_controller.rb', line 48

def update
  if @comment.update(content: params[:comment][:content])
    flash[:notice] = t('camaleon_cms.admin.comments.message.updated')
    redirect_to action: :index
  else
    render 'form'
  end
end