Skip to content

Instantly share code, notes, and snippets.

@batasrki
Created August 21, 2008 18:26
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 batasrki/6607 to your computer and use it in GitHub Desktop.
Save batasrki/6607 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
before_filter :find_post
skip_before_filter :check_login
def create
@comment = @post.comments.new
@comment.body = params[:comment][:body]
@comment.user_directory_id = @me.user_directory_id
respond_to do |format|
if @comment.save
flash[:notice] = "Thank you for your comment"
format.html { redirect_to user_post_url(@post.user_directory_id, @post) }
format.xml { render :xml => @comment, :status => :created, :location => [@post.user_directory_id, @post] }
else
flash[:error] = "Comment not posted"
format.html { redirect_to user_post_path(@post.user_directory_id, @post) }
format.xml { render :xml => @comment.errors, :status => :unprocessable_entity }
end
end
end
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.html { redirect_to user_post_url(@post.user_directory_id, @post)}
end
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