# Trying to update one collection\_select with the selection of another

**URL:** <https://www.ruby-forum.com/t/trying-to-update-one-collection-select-with-the-selection-of-another/185974>\
**Category:** Rails\
**Created:** [March 29, 2010, 10:49pm UTC](https://www.ruby-forum.com/t/trying-to-update-one-collection-select-with-the-selection-of-another/185974 "2010-03-29T22:49:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximulus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/82dd89/32.png) [@maximulus](https://www.ruby-forum.com/u/maximulus)\
**Post date:** [March 29, 2010, 10:49pm UTC](https://www.ruby-forum.com/t/trying-to-update-one-collection-select-with-the-selection-of-another/185974/1 "2010-03-29T22:49:41Z")

</div>

Hello,  
I’ve seen numerous tutorials on this but have yet to get anything  
working. It’s been about 5 days, and I am getting a little frustrated,  
so here goes

Here is the model:

items has\_many inventories  
inventory has\_many locations  
locations has\_many warehouses

Here is the view:

\<%= javascript\_include\_tag :defaults %\>

\<% form\_for (@item), :url=\> {:action =\> “create”, :id =\> @user.id} do |  
i| %\>  
\<%= i.text\_field :name %\>  
\<%= render :partial=\>‘getlocation’ %\>  
\<%= submit\_tag ‘Submit’ %\>  
\<% end %\>

getlocation.rhtml

Location: \<%= collection\_select :inventory, :location\_id,  
@locations, :id, :streetadrees1 %\>

 Warehouse location: \<%= collection\_select :inventory, :warehouse\_id, @warehouse, :id, :name %\>
 \<%= observe\_field("inventory\_location\_id", :frequency=\> 0.025, :update =\> "inventory\_warehouse\_id", :with =\> 'location\_id', :url =\> { :action =\> 'getlocation' } ) %\>

And the controller  
def new  
@location= Location.find(:first, :conditions=\>[‘primaryloc=?’, ‘1’]  
@locations = Location.find(:all)  
@warehouse = Warehouse.find(:all, :conditions=\>[‘location\_id=?’,  
@location.id])  
@item = @business.items.build  
end  
def getlocation

@location = Location.find(params[:location\_id])  
@locations = Location.find(:all)  
@warehouse = Warehouse.find(:all, :conditions=\>[‘location\_id=?’,  
@location.id])

render :partial =\> ‘getwarehouse’

end

Results: The javascript does pass to the params to the server when the  
location select menu changes, but the warehouse doesn’t seem to  
collect the new data, and update its list. Any ideas? Thanks in  
advance. (and yes, I need to use observe field, a totally client side  
solution will not work for my purposes).
