Class: CommentsController

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

Instance Method Summary collapse

Instance Method Details

#acceptObject



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

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

#acceptedObject



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

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

#blockObject



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

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

#blockedObject



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

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
30
31
# 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
    Activity.create doer_id: current_user.id, message: "left a comment attached to: #{view_context.link_to (@comment.commentable.try(:name) || @comment.commentable.try(:title) || 'unknown'), @comment.commentable}."
    redirect_to @comment.commentable, notice: t('comments.create.notice')
  else
    flash[:warning] = t('comments.create.warning')
    redirect_to @comment.commentable
  end
end

#destroyObject



43
44
45
46
47
# File 'app/controllers/comments_controller.rb', line 43

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



86
87
88
89
90
91
92
# File 'app/controllers/comments_controller.rb', line 86

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



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

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

#updateObject



33
34
35
36
37
38
39
40
41
# File 'app/controllers/comments_controller.rb', line 33

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