Skip to content

Instantly share code, notes, and snippets.

@seivan
Created March 15, 2009 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seivan/79562 to your computer and use it in GitHub Desktop.
Save seivan/79562 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
before_filter :blogpost_find
private
def blogpost_find
@blogpost = Blogpost.find(params[:blogpost_id])
end
def index
@comments = @blogpost.comments
end
def show
@comment = @blogpost.comments.find(params[:id])
end
def new
@comment = @blogpost.comments.build
end
def create
@comment = @blogpost.comments.build(params[:comment])
if @comment.save && @comment.code == "Hey Fishie"
redirect_to post_comment_url(@post, @comment)
else
render :action => "new"
end
end
def update
@comment = Comment.find(params[:id])
if @comment.update_attributes(params[:comment])
redirect_to post_comment_url(@post, @comment)
else
render :action => "edit"
end
end
def edit
@comment = @blogpost.comments.find(params[:id])
end
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.html { redirect_to post_comments_path(@post) }
format.xml { head :ok }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment