Using Array.each in a helper

hi all,

I’m trying to do a each on an array the droppable element
<%= draggable_element “user_” + create_drop_zone(zone),
:revert => true,
:onStart => “function(){” %>
<% drop_zone_ids.each do |
zone| %>
Element.addClassName(’<%=
zone %>’, ‘border’);
<% end %>
Element.addClassName(‘user_<%=
user_node %>’, ‘move_user’); }

This results in:
//

Element.addClassName(‘3’, ‘border’);
Element.addClassName(‘4’, ‘border’);
Element.addClassName(‘user_1_4’, ‘move_user’); }

Someone knows how to solve this?

thanks
Stijn

Hi –

On Fri, 7 Mar 2008, Tarscher wrote:

zone %>', ‘border’);
Element.addClassName(‘4’, ‘border’);
Element.addClassName(‘user_1_4’, ‘move_user’); }

You need to drop down to regular Ruby string interpolation. Try this:

<%= draggable_element “user_” + create_drop_zone(zone),
:revert => true,
:onStart => "function(){#{
drop_zone_ids.map do |zone|
“Element.addClassName(‘#{zone}’, ‘border’);
Element.addClassName(‘user_#{user_node}’, ‘move_user’);
"
end}
}” %>

David


Upcoming Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS, April 14-17 2008, New York City
CORE RAILS, June 24-27 2008, London (Skills Matter)
See http://www.rubypal.com for details. Berlin dates coming soon!