# Simple\_captcha + model

**URL:** <https://www.ruby-forum.com/t/simple-captcha-model/118148>\
**Category:** Rails\
**Created:** [October 24, 2007, 7:39am UTC](https://www.ruby-forum.com/t/simple-captcha-model/118148 "2007-10-24T07:39:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@Bala](https://www.ruby-forum.com/u/Bala)\
**Post date:** [October 24, 2007, 7:39am UTC](https://www.ruby-forum.com/t/simple-captcha-model/118148/1 "2007-10-24T07:39:28Z")

</div>

Hi Experts,

l have model called User  
class User \< ActiveRecord::Base  
apply\_simple\_captcha  
end

in view  
\<%= show\_simple\_captcha(:object=\>“user”) %\>

in controller  
@user = User.fiind(params[:id])  
if @user.valid\_with\_captcha?  
if @user.update\_attributes(params[:use])  
--------  
else  
---------  
end  
else  
--------------------  
end

as per this code is working fine, but all the text which i’ve entered  
in textfields are cleared, and shows error appropriate error like  
first\_name and last\_name is blank but i feeded all the data correct  
way except the captcha value, which shouldnt happen.

Plz help me guys, i’m stuck up with that

TIA,

Bala

---

<div class="post-metadata">

**Author:** ![Bala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/94ad74/32.png) [@Bala](https://www.ruby-forum.com/u/Bala)\
**Post date:** [October 24, 2007, 4:50pm UTC](https://www.ruby-forum.com/t/simple-captcha-model/118148/2 "2007-10-24T16:50:56Z")

</div>

First, it seems to me that a model is not where a captcha might want  
to go. I personally feel it should be in the controller and view, but  
not in the model.

That said, I have a helper method (well, once I refactor it out into a  
method) which generates the captcha (for the view) and a simple  
function which validates it and returns either :success, :failure, or  
nil. :success means it matched. :failure means it did not. nil  
means it could not perform the check, either because it could not  
reach the servers or some internal error to my code. I treat this as  
:success and move on.

–Michael
