# Xxx.valid? still true after xxx.errors.add(...)?

**URL:** <https://www.ruby-forum.com/t/xxx-valid-still-true-after-xxx-errors-add/165952>\
**Category:** Ruby\
**Created:** [April 20, 2009, 11:06am UTC](https://www.ruby-forum.com/t/xxx-valid-still-true-after-xxx-errors-add/165952 "2009-04-20T11:06:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 20, 2009, 11:06am UTC](https://www.ruby-forum.com/t/xxx-valid-still-true-after-xxx-errors-add/165952/1 "2009-04-20T11:06:32Z")

</div>

Hi all

I have the following code in my controller:

```
if @comment.valid?
  captcha_url =

```

“[http://captchator.com/captcha/check\_answer/#{captcha\_code}/#{@comment.captcha}](http://captchator.com/captcha/check_answer/#%7Bcaptcha_code%7D/#%7B@comment.captcha%7D)”  
result = open(captcha\_url)  
unless result.read == “1”  
@comment.errors.add(:captcha, “Captcha wurde nicht korrekt  
eingegeben”)  
raise “#{@comment.valid?}”  
end  
end

Although I’m adding an error to :captcha, when I raise @comment.valid?  
on the next line this still gives me true! Why is that? I just added an  
error to @comment, didn’t I?!

Thanks  
Josh

---

<div class="post-metadata">

**Author:** ![josh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/45deac/32.png) [@josh](https://www.ruby-forum.com/u/josh)\
**Post date:** [April 20, 2009, 11:16am UTC](https://www.ruby-forum.com/t/xxx-valid-still-true-after-xxx-errors-add/165952/2 "2009-04-20T11:16:39Z")

</div>

I’m sorry, this belongs to the RoR part of this forum… I’ll re-post it  
there.
