Denise Robinson
2007-Dec-13 14:21 UTC
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!
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---