rubyonrailsin

A Ruby and Rails talk

Monday, March 29, 2010


[Rails] trying to update one collection_select with the selection of another

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

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 %>
<br>

<div id="inventory_location_id"> Warehouse location: <%=
collection_select :inventory, :warehouse_id, @warehouse, :id, :name
%></div>
<%= 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).

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive