Forum: Ruby on Rails options_from_collection_for_select - NIL Object

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.
mike (Guest)
on 2006-01-04 00:20
i am kind of desparated

i try with options_from_collection_for_select to get option values, but
it says

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

but @customers is not empty ->

def get_customer

i have tested it and also the attributes "id" and "name" are existing!!

<h1> xy </h1>

<%=start_form_tag :action => 'get_article' %>

<select name=xy>
<%= options_from_collection_for_select (@customers, "id", "name") %>

<%= submit_tag "Get" %>

<%= end_form_tag %>
Wilson B. (Guest)
on 2006-01-04 02:53
(Received via mailing list)
Assuming the rhtml code you pasted is from get_customer.rhtml, I don't
see anything wrong with the code.
I personally use 'select()' more often than 'options_from_etc_etc',
but in this case you're not working with any objects that exist yet,
but rather passing the selection as a parameter to a different action.
 What you've got should be fine.

What do you get when you put <%= debug(@customers) %> right under the
<h1> tag in your RHTML source?
This topic is locked and can not be replied to.