On Aug 16, 2009, at 3:57 PM, Philip Gavrilos wrote:

>
> Steve Ross wrote:
>> On Aug 16, 2009, at 3:01 PM, Philip Gavrilos 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
> pa...@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

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to