Forum: Ruby on Rails collection_select and validation problems

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Phillip Novess (Guest)
on 2006-05-15 20:52
(Received via mailing list)
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:         <td>Vendor</td>
20:         <td>
21:             <!-- vendors -->
22:             <%= collection_select("pricing_survey", "vendor_id",
@vendors, :id, :vendor_name, { :prompt => true } ) %></td>
23:     </tr>
24:     <tr>
25:         <td>Retailer</td>



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
oom tuinstoel (Guest)
on 2006-05-15 21:27
In the new and update methods of your controller (presumably
pricing_survey_controller?) you should have something like

@vendors = Vendor.find(:all).
Phillip Novess (Guest)
on 2006-05-16 01:33
(Received via mailing list)
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/.
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
This topic is locked and can not be replied to.