# Collection\_select and validation problems

**URL:** <https://www.ruby-forum.com/t/collection-select-and-validation-problems/94820>\
**Category:** Rails\
**Created:** [May 15, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/collection-select-and-validation-problems/94820 "2006-05-15T18:52:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_Novess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/edb3f5/32.png) [@Phillip\_Novess](https://www.ruby-forum.com/u/Phillip_Novess)\
**Post date:** [May 15, 2006, 6:52pm UTC](https://www.ruby-forum.com/t/collection-select-and-validation-problems/94820/1 "2006-05-15T18:52:35Z")

</div>

I keep getting the error below when I use validations with  
collection\_select.

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.inject

Extracted source (around line #22):

19:

Vendor  
20:   
21:   
22: \<%= collection\_select(“pricing\_survey”, “vendor\_id”,  
@vendors, :id, :vendor\_name, { :prompt =\> true } ) %\>  
23:   
24:   
25: Retailer

Does anybody have any ideas? I assume that rails is not querying the  
DB for the collection for my drop downs when an error occurs.

Thanks,  
Phill

---

<div class="post-metadata">

**Author:** ![Phillip\_Novess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/edb3f5/32.png) [@Phillip\_Novess](https://www.ruby-forum.com/u/Phillip_Novess)\
**Post date:** [May 15, 2006, 7:27pm UTC](https://www.ruby-forum.com/t/collection-select-and-validation-problems/94820/2 "2006-05-15T19:27:06Z")

</div>

In the new and update methods of your controller (presumably  
pricing\_survey\_controller?) you should have something like

@vendors = Vendor.find(:all).

---

<div class="post-metadata">

**Author:** ![Phillip\_Novess](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/edb3f5/32.png) [@Phillip\_Novess](https://www.ruby-forum.com/u/Phillip_Novess)\
**Post date:** [May 15, 2006, 11:33pm UTC](https://www.ruby-forum.com/t/collection-select-and-validation-problems/94820/3 "2006-05-15T23:33:19Z")

</div>

I have that for the new and edit methods but not the update and create  
methods. I saw somewhere else that I need to explicitly call the new  
method from within create.

So instead of:

else  
render :action =\> ‘new’  
end

Do this…

else  
new  
render :action =\> ‘new’  
end

However, now Iose my validation messages. Also it doesn’t seem to  
conform to the DRY method if I’m calling find in every method within my  
controller.

Any other suggestions?

Thanks,  
phill

On May 15, 2006, at 11:27 AM, oom tuinstoel wrote:

In the new and update methods of your controller (presumably  
pricing\_survey\_controller?) you should have something like

@vendors = Vendor.find(:all).

–  
Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

* * *

Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
