Created
October 17, 2010 08:03
-
-
Save Arcath/630653 to your computer and use it in GitHub Desktop.
Nested model create action using SpamHam
This file contains hidden or 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
def create | |
@post = Post.find(params[:post_id]) if params[:post_id] | |
@post = Post.find(params[:comment][:post_id]) if params[:comment][:post_id] | |
@comment = @post.comments.new(params[:comment]) | |
@comment.user_id = current_user.id if current_user | |
if @comment.body.spam? then | |
unless params[:recaptcha_challenge_field] then | |
flash[:error] = "Comment looks like Spam" | |
render :action => 'new' | |
else | |
if validate_recap(params, @comment.errors) && @comment.save then | |
flash[:notice] = "Successfully created comment." | |
redirect_to @comment.post | |
else | |
render :action => 'new' | |
end | |
end | |
else | |
if @comment.save | |
flash[:notice] = "Successfully created comment." | |
redirect_to @comment.post | |
else | |
render :action => 'new' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment