# Captcha in a belongs\_to

**URL:** <https://www.ruby-forum.com/t/captcha-in-a-belongs-to/186398>\
**Category:** Rails\
**Created:** [April 6, 2010, 2:03pm UTC](https://www.ruby-forum.com/t/captcha-in-a-belongs-to/186398 "2010-04-06T14:03:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 6, 2010, 2:03pm UTC](https://www.ruby-forum.com/t/captcha-in-a-belongs-to/186398/1 "2010-04-06T14:03:57Z")

</div>

Hi  
I am using simple\_captcha. I have two models User and Staff.  
Relation ship are

User has\_one staff  
staff belongs\_to user

```
 Now in the staff edit I have to include a captcha. I did like

```

\<% form\_for @user, :url =\> staff\_url([@staff](https://www.ruby-forum.com/groups/staff)), :html =\> {:method =\> :put  
} do |f|%\>

\<%= f.text\_field :first\_name,:maxlength =\> 50 %\>

  

\<%= show\_simple\_captcha :image\_style =\> ‘random’,:distortion =\>  
‘medium’ %\>

  
\<%end %\>

And in staff.rb  
apply\_simple\_captcha :message =\> “Verification code does not match with  
image.”

And in update action of of staff controller

def update  
[@staff](https://www.ruby-forum.com/groups/staff) = Staff.find(params[:id])  
@user = @staff.user  
if @staff.valid\_with\_captcha? and  
@user.update\_attributes(params[:user])  
flash[:notice] = “check your mail "  
redirect\_to login\_url  
else  
flash.now[:error] = @staff.errors.full\_messages.join(”  
")  
#This I wrote deliberately  
render :action =\> :edit  
end  
end

But even I put the correct captcha code and submit , it always shows  
message  
“Verification code does not match with image.”. Dont know why please  
help

Note:

```
   The params are like

```

{“user”=\>{“first\_name”=\>“Tom”, “last\_name”=\>""}, “action”=\>“update”,  
“\_method”=\>“put”,  
“authenticity\_token”=\>“0OWRFPssTgTqCUESex7LrJ2QQ7HWSiAQxtiMhQm/N1s=”,  
“captcha”=\>“PYESEZ”, “id”=\>“10”, “controller”=\>“staff”}

Thanks in advance  
Tom

---

<div class="post-metadata">

**Author:** ![tom-mac](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/bc8723/32.png) [@tom-mac](https://www.ruby-forum.com/u/tom-mac)\
**Post date:** [April 7, 2010, 6:19am UTC](https://www.ruby-forum.com/t/captcha-in-a-belongs-to/186398/2 "2010-04-07T06:19:25Z")

</div>

Hi  
Anybody please help. This still i can’t solve

Tom
