Skip to content

Instantly share code, notes, and snippets.

@skalnik
Created December 30, 2008 01:21
Show Gist options
  • Save skalnik/41472 to your computer and use it in GitHub Desktop.
Save skalnik/41472 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
before_filter :find_post
before_filter :authenticate, :only => :destory
def new
@comment = @post.comments.build
end
def create
@comment = @post.comments.build(params[:comment])
if @comment.save
flash[:notice] = 'Comment was successfully created.'
else
flash[:notice] = 'There was a trouble saving your comment'
end
redirect_to @post
end
def destroy
@comment = @post.comments.find(params[:id])
@comment.destroy
redirect_to @post
end
protected
def find_post
@post = Post.find(params[:post_id])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment