Class: CommentsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
# File 'app/controllers/comments_controller.rb', line 25

def create
  @comment = @model.create_comment!(params[:comment])
  if @comment.save
    flash[:notice] = 'Comment was successfully created.'
  else
    flash[:error] = 'Comment wasn\'t created.'
  end
  respond_with(@model)
end

#destroyObject



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

def destroy
  @comment.destroy
  respond_with(@model)
end

#editObject



21
22
23
# File 'app/controllers/comments_controller.rb', line 21

def edit
  respond_with([@model,@comment])
end

#indexObject



8
9
10
11
# File 'app/controllers/comments_controller.rb', line 8

def index
  @comments = @model.comments
  respond_with([@model,@comments])
end

#newObject



17
18
19
# File 'app/controllers/comments_controller.rb', line 17

def new
  respond_with([@model,@comment = Comment.new(:parent => params[:parent])])
end

#showObject



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

def show
  respond_with([@model,@comment])
end

#updateObject



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

def update
  if @comment.update_attributes(params[:comment])
    flash[:notice] = 'Comment was successfully updated.'
  else
    flash[:error] = 'Comment wasn\'t deleted.'
  end
  respond_with([@model,@comment], :location => @model)
end