add html titles to these pages
[kwestie.git] / app / controllers / comments_controller.rb
blob2098ec3d5d7f73c3fe46fd8d34cc33d0560de3bb
1 class CommentsController < ApplicationController
3   before_filter :login_required, :only => [ :new, :create, :edit, :update, :destroy]
5   # GET /comments
6   # GET /comments.xml
7   def index
8     @comments = Comment.find(:all)
10     respond_to do |format|
11       format.html { render :xml => @comments.to_xml }
12       format.xml  { render :xml => @comments.to_xml }
13     end
14   end
16   # GET /comments/1 - comments are not accessed individually like this
17   # GET /comments/1.xml
18   def show
19     @comment = Comment.find(params[:id])
21     respond_to do |format|
22       format.html { render :partial => 'show', :locals => { :comment => @comment } }
23       format.xml  { render :xml => @comment.to_xml }
24     end
25   end
27   # GET /comments/1;edit
28   def edit
29     @comment = Comment.find(params[:id])
30   end
32   # POST /comments
33   # POST /comments.xml
34   def create
35     @comment = Comment.new(params[:comment])
37     respond_to do |format|
38       if @comment.save
39         flash[:notice] = 'Comment was successfully created.'
40         format.html { redirect_to issue_url(@comment.issue)  }
41         format.xml  { head :created, :location => comment_url(@comment) }
42       else
43         format.html { redirect_to issue_url(@comment.issue) }
44         format.xml  { render :xml => @comment.errors.to_xml }
45       end
46     end
47   end
49   # PUT /comments/1
50   # PUT /comments/1.xml
51   def update
52     @comment = Comment.find(params[:id])
54     respond_to do |format|
55       if @comment.update_attributes(params[:comment])
56         flash[:notice] = 'Comment was successfully updated.'
57         format.html { redirect_to comment_url(@comment) }
58         format.xml  { head :ok }
59       else
60         format.html { render :action => "edit" }
61         format.xml  { render :xml => @comment.errors.to_xml }
62       end
63     end
64   end
66   # DELETE /comments/1
67   # DELETE /comments/1.xml
68   def destroy
69     @comment = Comment.find(params[:id])
70     @comment.destroy
72     respond_to do |format|
73       format.html { redirect_to comments_url }
74       format.xml  { head :ok }
75     end
76   end
77 end