Class: CommentsController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/generators/templates/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
# File 'lib/generators/templates/comments_controller.rb', line 14

def create
  @comment = Comment.new(params[:comment])
  if @comment.save
    redirect_to article_url(params[:article_id])
  else
    render :new
  end
end

#destroyObject



37
38
39
40
41
# File 'lib/generators/templates/comments_controller.rb', line 37

def destroy
  @comment = Comment.find( params[:id] )
  @comment.destroy
  redirect_to article_url(params[:article_id])
end

#editObject



23
24
25
26
# File 'lib/generators/templates/comments_controller.rb', line 23

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

#indexObject



4
5
6
7
# File 'lib/generators/templates/comments_controller.rb', line 4

def index
  @comments = Comment.where(:article_id => params[:article_id]).all
  respond_with(@comments)
end

#newObject



9
10
11
12
# File 'lib/generators/templates/comments_controller.rb', line 9

def new
  @comment = Comment.new
  respond_with(@comments)
end

#updateObject



28
29
30
31
32
33
34
35
# File 'lib/generators/templates/comments_controller.rb', line 28

def update
  @comment = Comment.find( params[:id] )
  if @comment.update_attributes(params[:comment])
    redirect_to article_url(params[:article_id])
  else
    render :edit
  end
end