Class: CommentsController

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

Instance Method Summary collapse

Instance Method Details

#acceptObject



46
47
48
49
50
51
52
53
54
# File 'app/controllers/comments_controller.rb', line 46

def accept
  @comment = Comment.find params[:id]
  @comment.status = 'accepted'
  if @comment.save
    redirect_to :back, notice: t('comments.moderation.accept.notice')
  else
    redirect_to comments_path, warning: t('comments.moderation.accept.warning')
  end
end

#acceptedObject



71
72
73
74
# File 'app/controllers/comments_controller.rb', line 71

def accepted
  @comments = Comment.accepted.by_recent.paginate(:page => params[:page], :per_page => 50)
  switch_to_admin_layout
end

#blockObject



56
57
58
59
60
61
62
63
64
# File 'app/controllers/comments_controller.rb', line 56

def block
  @comment = Comment.find params[:id]
  @comment.status = 'blocked'
  if @comment.save
    redirect_to :back, notice: t('comments.moderation.block.notice')
  else
    redirect_to comments_path, warning: t('comments.moderation.block.warning')
  end
end

#blockedObject



76
77
78
79
# File 'app/controllers/comments_controller.rb', line 76

def blocked
  @comments = Comment.blocked.by_recent.paginate(:page => params[:page], :per_page => 50)
  switch_to_admin_layout
end

#createObject



19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/comments_controller.rb', line 19

def create
  @comment = Comment.new(comment_params)
  @comment.author_id = current_user.id
  @comment.locale = I18n.locale.to_s
  @comment.status = 'pending' # translation not done with globalize3 but with locale files upon showing status to user
  if @comment.save
    redirect_to @comment.page, notice: t('comments.create.notice')
  else
    redirect_to @comment.page, warning: t('comments.create.warning')
  end
end

#destroyObject



40
41
42
43
44
# File 'app/controllers/comments_controller.rb', line 40

def destroy
  @comment = Comment.find(params[:id])
  @comment.destroy
  redirect_to comments_url, notice: t('comments.destroy.notice')
end

#editObject

comments are shown within a page new comments are created by users from within a page



14
15
16
17
# File 'app/controllers/comments_controller.rb', line 14

def edit
  @comment = Comment.find(params[:id])
  switch_to_admin_layout
end

#for_feedObject



81
82
83
84
85
86
87
# File 'app/controllers/comments_controller.rb', line 81

def for_feed
  @comments = Comment.showable.for_locale(I18n.locale).by_recently_created.limit(50)
  respond_to do |format|
    format.html { redirect_to root_path }
    format.atom
  end
end

#indexObject



6
7
8
9
# File 'app/controllers/comments_controller.rb', line 6

def index
  @comments = Comment.by_recent.paginate(:page => params[:page], :per_page => 50)
  switch_to_admin_layout
end

#pendingObject



66
67
68
69
# File 'app/controllers/comments_controller.rb', line 66

def pending
  @comments = Comment.pending.by_created.paginate(:page => params[:page], :per_page => 50)
  switch_to_admin_layout
end

#updateObject



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

def update
  @comment = Comment.find(params[:id])
  if @comment.update_attributes(comment_params)
    redirect_to comments_path, notice: t('comments.update.notice')
  else
    render action: "edit", warning: t('comments.update.warning'), layout: 'admin'
  end
end