[LRUG] [RoR] Problem observing multiple fields
Jordi Noguera Leon
jordinoguera83 at gmail.com
Tue Sep 22 05:26:21 PDT 2009
Hi all!!
I've got the following problem: I have a collection of items, each of one
having a drop down list, for a given field. I'd like to trigger an action
every time a selection is done in any of the lists. This is what I've done
(more or less...):
<% @items.each do |item| %>
<%= collection_select(:subitem, :id, item.find.whatever, :id, :description)
% >
<%= observe_field :subitem_id, :url => { :action => 'some_action' }, :with
=> :subitem_id %>
<% end %>
I'd say, at some point it worked, but now it only works for the first item. For
the other items, no action is triggered... So, I thought that maybe the
problem was that all the fields had the same name. And then, I've tried it
putting a different name to each one:
<% @items.each do |item| %>
<%= collection_select(*'subitem' + item.id.to_s*, *'id'*,
item.find.whatever, :id, :description) % >
<%= observe_field* 'subitem' + item.id.to_s + '_id'*, :url => { :action =>
'some_action' }, :with => :subitem_id %>
<% end %>
This thing works fine, but I think it's quite ugly... Does anyone know of a
better solution?
Thanks!
Jordi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20090922/78a40378/attachment-0003.html>
More information about the Chat
mailing list