# Getting drop-down selection on a "new" view to controller

**URL:** <https://www.ruby-forum.com/t/getting-drop-down-selection-on-a-new-view-to-controller/123030>\
**Category:** Rails\
**Created:** [December 13, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/getting-drop-down-selection-on-a-new-view-to-controller/123030 "2007-12-13T15:21:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorgeoussoul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6f9a4e/32.png) [@gorgeoussoul](https://www.ruby-forum.com/u/gorgeoussoul)\
**Post date:** [December 13, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/getting-drop-down-selection-on-a-new-view-to-controller/123030/1 "2007-12-13T15:21:15Z")

</div>

On a “new” view, there’s two drop-down lists - Company and Contact.  
They both display the name, but store the id. After changing the  
company drop-down list, I want to limit the Contact drop-down list to  
only Contacts for the selected Company.

I added a function call to the OnChange event of the company drop-down  
list:  
{:onChange =\> remote\_function(:url =\> { :action =\>  
‘update\_contact\_list’, :company\_id =\> quote.company\_id }) }

And then I have this is the Controller:  
def update\_contact\_list  
@company = Company.find(params[:company\_id])  
@contact\_list = Contact.find(:all, :order =\> :first\_name,  
:conditions =\> [“company\_id =?”, @company])  
render :update do |page|  
page.replace\_html ‘contact\_list’, ‘collection\_select :quote,  
:contact\_id, @contact\_list, :id, :first\_name, { :include\_blank =\> true,  
:multiple =\> false } , :html =\> { :id =\> “contact\_list” }’

```
  end

```

end

It’s complaining that “quote” (in the “quote.company\_id” part of the  
OnChange code in the view) is nil. Which I suppose it is, since the  
record hasn’t been saved yet. What’s the best way to handle that? The  
company drop-down is the first thing on the page (or in other words,  
it’s the first field users are going to enter data into - so, saving the  
record before they get to that point isn’t a great option). Is there  
another way to pass the value they just selected to the controller?

Thanks!
