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 @customers=Customer.find_all end 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") %> </select> <%= submit_tag "Get" %> <%= end_form_tag %> -- Posted via http://www.ruby-forum.com/.
Wilson Bilkovich
2006-Jan-04 00:51 UTC
[Rails] options_from_collection_for_select - NIL Object
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? On 1/3/06, mike <mikke331@yahoo.de> wrote:> 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 > @customers=Customer.find_all > end > > 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") %> > </select> > > <%= submit_tag "Get" %> > > <%= end_form_tag %> > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >