Bug #3184: Unable to validates_presence_of if collection_select in form.
http://redmine.ruby-lang.org/issues/show/3184

Author: mike montagne
Status: Open, Priority: Normal
ruby -v: 1.8.7 (2009-06-08 patchlevel 173) [universal-darwin10.0]

I have a working collection_select object in a form which works flawlessly if no validation methods are applied to the model:

<%= f.collection_select(:language_id, @languages, :id, :language_ref_name, options ={}, :class =>"Select_250") %>

The implementation displays a string field, but assigns an integer value from the FK table to the language_id field of the members table to which this form is applied. 

If there are no validation calls in my model, my edit and new/create forms work fine with this collection_select. But if I add any validation method calls to the model, any invalid field value raises the same kind of error, pointing to my collection_select:

 NoMethodError in Members#update

Showing app/views/members/edit.html.erb where line #27 raised:

You have a nil object when you didn't expect it!

----------

If I pull the collection_select out of the form, it validates fine. 

Because it's the developer's responsibility to effectively validate with the collection_select itself, I would think a valid fix for this issue would be to simply ignore the presences of collection_select objects in the form.

Thanks, 

mike
You might have expected an instance of Array.
The error occurred while evaluating nil.map

Extracted source (around line #27):

24: 
25: 
26: <p class="FormLabel_TopMandatory"><%= f.label :language_id %></p>
27: <%= f.collection_select(:language_id, @languages, :id, :language_ref_name, options ={}, :class =>"Select_250") %>
28: 
29: 
30: <p class="FormLabel_TopMandatory"><%= f.label :ip %></p>


----------------------------------------
http://redmine.ruby-lang.org