any help with captcha in my comments ?

this is my error:

Processing ApplicationController#create (for 127.0.0.1 at 2009-08-17 00:57:56) [POST]   Parameters: {"comment"=>{"name"=>"asdasd", "body"=>"asdasd"}, "commit"=>"Add Comment", "post_id"=>"19", "authenticity_token"=>"B5dll5fTaDO+ZrEs1S0KkYsmK8VMzCOeDEf731w21zY=", "captcha"=>"asdasd", "_"=>""}

SyntaxError (/Users/webstic/Sites/weblog/app/controllers/comments_controller.rb:11: syntax error, unexpected kELSE, expecting kEND       else           ^):

this is my code:

class CommentsController < ApplicationController   include SimpleCaptcha::ControllerHelpers

  def create     if simple_captcha_valid?     @post = Post.find(params[:post_id])     @comment = @post.comments.create!(params[:comment])     respond_to do |format|       format.html { redirect_to @post }       format.js       else         flash[:notice] = "please right down the image verification"       end     end   end end

any suggestions ?

def create if simple_captcha_valid? @post = Post.find(params[:post_id]) @comment = @post.comments.create!(params[:comment]) respond_to do |format| format.html { redirect_to @post } format.js else flash[:notice] = "please right down the image verification" end end end end

any suggestions ?

That's not syntactically correct ruby - you need to end the respond_to block before the else

Fred

this is my error:

Processing ApplicationController#create (for 127.0.0.1 at 2009-08-17 00:57:56) [POST] Parameters: {"comment"=>{"name"=>"asdasd", "body"=>"asdasd"}, "commit"=>"Add Comment", "post_id"=>"19", "authenticity_token"=>"B5dll5fTaDO+ZrEs1S0KkYsmK8VMzCOeDEf731w21zY=", "captcha"=>"asdasd", "_"=>""}

SyntaxError (/Users/webstic/Sites/weblog/app/controllers/comments_controller.rb: 11: syntax error, unexpected kELSE, expecting kEND      else          ^):

this is my code:

class CommentsController < ApplicationController include SimpleCaptcha::ControllerHelpers

def create    if simple_captcha_valid?    @post = Post.find(params[:post_id])    @comment = @post.comments.create!(params[:comment])    respond_to do |format|      format.html { redirect_to @post }      format.js    end # respond_to

# Move the else out of the respond_to block. If you redo your
indentation, it will become more obvious.

Steve Ross wrote:

SyntaxError include SimpleCaptcha::ControllerHelpers

def create    if simple_captcha_valid?    @post = Post.find(params[:post_id])    @comment = @post.comments.create!(params[:comment])    respond_to do |format|      format.html { redirect_to @post }      format.js    end # respond_to

# Move the else out of the respond_to block. If you redo your indentation, it will become more obvious.

     else        flash[:notice] = "please right down the image verification"      end # if

i change to this:

class CommentsController < ApplicationController   include SimpleCaptcha::ControllerHelpers

  def create     if simple_captcha_valid?     @post = Post.find(params[:post_id])     @comment = @post.comments.create!(params[:comment])     respond_to do |format|       format.html { redirect_to @post }       format.js     end           else         flash[:notice] = "please right down the image verification"     end   end end

( i post and create js also)

page.insert_html :bottom, :comments, :partial => @comment page[@comment].visual_effect :highlight page[:new_comment].reset

but now if post the comment with right capcha everything is ok but if im wrong i have js error on my code (browser popups) before flash[:notice] = "please right down the image verification"

any suggestion ?

thanks for your help guys !

Well, you're setting the flash, but not telling your method what to render, so it's rendering (by default) create.html.erb, if it exists. You should look at your logs to see what the exact error is. The logic in your create method really doesn't handle this right. You should be doing the test up front, above the respond_to block. So, kind of like:

def create    if simple_captcha_valid?      @post = Post.find(params[:post_id])      @comment = @post.comments.create!(params[:comment])    else      flash[:notice] = "please right down the image verification"    end

   respond_to do |format|      format.html { @post.valid? ? redirect_to @post : render :action => :new }      format.js    end end

# create.rjs if you are using prototype. I'm not sure of the exact syntax here, but # you get the idea. Something has to send back the js to make the error appear. Nothing # will be rendered on success if flash[:error] # when errors are present    page.update :flash_error, flash[:notice] end