Forum: Ruby on Rails Validation issues

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Buntin, Seth - KATE (Guest)
on 2006-02-21 22:00
(Received via mailing list)
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

  validates_presence_of :title

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

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:     <p><label for="resource_focus_id">Focus</label><br/>
16:     <select name="resource[focus_id]" id="resource_focus_id">
17:         <option value="" selected="selected"></option>
18:     <% for @focus in @focuses %>
19:         <option value="<%= %>"><%= %></option>
20:     <% end %>
21:     </select>

Seth B.

Web Resources Coordinator

Kentucky Academy of Technology Education

Murray State University
Craig W. (Guest)
on 2006-02-21 22:16
(Received via mailing list)
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!   # 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

Nick S. (Guest)
on 2006-02-21 22:25
(Received via mailing list)
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

Try adding this before you render the form again:
@focuses = Focus.find :all
Neil D. (Guest)
on 2006-02-22 04:51
(Received via mailing list)
Buntin, Seth - KATE wrote:
> |21:     </select>|

You should probably confirm what is in focuses with something like
<!-- <%= forcuses.inspect() %> -->
I think you will find focuses is a 'nil'

I think this should be using a local variable

<% for focus in @focuses %>|
   <option value="<%= %>"><%= %></option>|
<% end %>|

> Murray State University

Regards Neil.
This topic is locked and can not be replied to.