Skip to content

Instantly share code, notes, and snippets.

@Arcath
Created October 17, 2010 08:03
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 Arcath/630653 to your computer and use it in GitHub Desktop.
Save Arcath/630653 to your computer and use it in GitHub Desktop.
Nested model create action using SpamHam
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