class CommentsController < ApplicationController before_filter :find_post # POST /comments # POST /comments.xml def create @comment = @post.comments.build(params[:comment]) respond_to do |format| if @comment.save flash[:notice] = 'Comment was successfully created.' format.html { redirect_to comment_url(@post, @comment) } format.xml { head :created, :location => comment_url(@post, @comment) } else format.html { render :action => "new" } format.xml { render :xml => @comment.errors.to_xml } end end end # DELETE /comments/1 # DELETE /comments/1.xml def destroy @comment = @post.comments.find(params[:id]) @comment.destroy respond_to do |format| format.html { redirect_to comments_url(@post) } format.xml { head :ok } end end private def find_post @post = Post.find_by_permalink(params[:post_id]) end end