Created
March 15, 2009 22:31
-
-
Save seivan/79562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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