Class: Admin::CommentsController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject



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

def destroy
  unless request.delete?
    flash[:notice] = "you can't destroy a comment by get request"
    redirect_to admin_comments_url
    return
  end
  comment = Comment.find(params[:id])
  comment.destroy
  flash[:notice] = "Comment destroy"
  redirect_to admin_comments_url
end

#editObject

View the edit page of comment



30
31
32
# File 'app/controllers/admin/comments_controller.rb', line 30

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

#indexObject

The index of comments view in admin



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

def index
  @comments = Comment.paginate :all, :page => params[:page],
    :per_page => 20, :order => 'created_at DESC'
end

#showObject

See a comment specific with params. If no comment, render a 404



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

def show
  @comment = Comment.find params[:id]
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/admin/comments_controller.rb', line 34

def update
  unless request.put?
    flash[:notice] = "you can't update a comment by get request"
    redirect_to admin_comments_url
    return
  end
  @comment = Comment.find params[:id]
  if @comment.update_attributes(params[:comment])
    flash[:notice] = "Comment is update"
    redirect_to admin_comments_url
  else
    render :action => 'edit'
  end
end