Class: CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @commentable = find_commentable
  @comment = @commentable.comments.build(params[:comment])
  @comment.user = current_user
  if @comment.save
    @comment.update_attributes(params[:comment])
    @comment.update_attributes(:active => true)
    flash[:notice] = t(:comment_created_successfully)
    redirect_to_ref_url
  else
    flash.now[:error] = t(:comment_created_unsuccessfully)
    render :new
  end
end

#destroyObject



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

def destroy
  @comment = Comment.find(params[:id])
  if @comment.destroy
    flash[:notice] = "The comment was deleted"
  end
  redirect_to(:back)
end

#editObject



36
37
# File 'app/controllers/comments_controller.rb', line 36

def edit
end

#newObject



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

def new
end

#showObject



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

def show
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/comments_controller.rb', line 39

def update
  if @comment.active == false
    @comment.update_attributes(:active => true)
    @hide = 'Hide Comment'
  elsif @comment.active == true
    @comment.update_attributes(:active => false)
    @hide = 'Unhide Comment'
  end

  if @comment.save
    if @comment.active == false
      flash[:notice] = "The comment has been hidden."
    else
      flash[:notice] = "The comment is no longer hidden."
    end
  end
  redirect_to(:back)
end