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

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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs