# Validation issues

**URL:** <https://www.ruby-forum.com/t/validation-issues/71536>\
**Category:** Rails\
**Created:** [February 21, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/validation-issues/71536 "2006-02-21T21:00:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BuntinS\_SethSKATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@BuntinS\_SethSKATE](https://www.ruby-forum.com/u/BuntinS_SethSKATE)\
**Post date:** [February 21, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/validation-issues/71536/1 "2006-02-21T21:00:51Z")

</div>

I have a form. Everything submits into the database if I don’t have any  
validation rules. When I put these rules:

validates\_uniqueness\_of :title, :message =\> “already exists in  
database”

validates\_presence\_of :title

I get this error (which seems weird because I am not validating against  
that):

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.each

Extracted source (around line #18):

15:

Focus  
  
16:   
17:   
18: \<% for @focus in @focuses %\>  
19: \<%= @focus.name %\>  
20: \<% end %\>  
21:

Seth B.

Web Resources Coordinator

Kentucky Academy of Technology Education

Murray State University

---

<div class="post-metadata">

**Author:** ![BuntinS\_SethSKATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@BuntinS\_SethSKATE](https://www.ruby-forum.com/u/BuntinS_SethSKATE)\
**Post date:** [February 21, 2006, 9:16pm UTC](https://www.ruby-forum.com/t/validation-issues/71536/2 "2006-02-21T21:16:14Z")

</div>

On Tue, 2006-02-21 at 13:59 -0600, Buntin, Seth - KATE wrote:

> 

* * *

I’m working on a very similar thing - I can’t get the validations to  
work (separate thread)

In your case, if you add ! to your controller…

if focus.save! # I’m guessing that it’s a ‘focus’ you are  
trying to save

Then you will get an active record error instead of the meaningless view  
code error

Craig

---

<div class="post-metadata">

**Author:** ![BuntinS\_SethSKATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@BuntinS\_SethSKATE](https://www.ruby-forum.com/u/BuntinS_SethSKATE)\
**Post date:** [February 21, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/validation-issues/71536/3 "2006-02-21T21:25:27Z")

</div>

Its because you are redisplaying your form with out reloading the  
options for your form. The render method does just that, it simply  
renders the view, it doesn’t call any other methods in your  
controller.

Try adding this before you render the form again:  
@focuses = Focus.find :all

---

<div class="post-metadata">

**Author:** ![BuntinS\_SethSKATE](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@BuntinS\_SethSKATE](https://www.ruby-forum.com/u/BuntinS_SethSKATE)\
**Post date:** [February 22, 2006, 3:51am UTC](https://www.ruby-forum.com/t/validation-issues/71536/4 "2006-02-22T03:51:59Z")

</div>

Buntin, Seth - KATE wrote:

> |21: |

You should probably confirm what is in focuses with something like

I think you will find focuses is a ‘nil’

I think this should be using a local variable

\<% for focus in @focuses %\>|

 \<%= focus.name %\>| \<% end %\>|

> Murray State University

Regards Neil.
