# Creating a simple drop-down list

**URL:** <https://www.ruby-forum.com/t/creating-a-simple-drop-down-list/104625>\
**Category:** Rails\
**Created:** [May 20, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/creating-a-simple-drop-down-list/104625 "2007-05-20T22:29:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![longint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8e7dd6/32.png) [@longint](https://www.ruby-forum.com/u/longint)\
**Post date:** [May 20, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/creating-a-simple-drop-down-list/104625/1 "2007-05-20T22:29:19Z")

</div>

Hey folks,

I’m having major issues trying to complete a simple task.

Goal:  
Create a drop-down list and populate it with states. When the user  
fills out the form and saves, the state selected should be saved with  
the record.

Problem:  
When trying to save the record I get the following error:

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

And it points to this line in my .rthml:

\<%= select\_tag ‘state’, options\_for\_select(@states) %\>

And here is my controller code in the ‘new’ method:

def new  
@client = Client.new  
@states = %w{-select- AL AK AZ AR CA CO CT DE DC FL GA HI ID IL IN  
IA KS KY  
LA ME MH MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND  
OH OK  
OR PA RI SC SD TN TX UT VT VI VA WA WV WI WY}  
end

The list populates fine with states, but bombs when I try to save.  
Please help.

Thanks.
