Collection_select and validation problems

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

In the new and update methods of your controller (presumably
pricing_survey_controller?) you should have something like

@vendors = Vendor.find(:all).

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
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails