I wasn't terribly clear.  Let me rephrase -- if you do this:

 urls.each do |url|
   link url, :click => Proc.new { window { image url } }
 end

Then every link will open the same image url (since all the created
Procs reference the same variable, which ends up with the same final
value).  However, if you do this:

 def make_image_callback(url)
   Proc.new { window { image url } }
 end

 image_urls.each do |image_url|
   link image_url, :click => make_image_callback(image_url)
 end

Then the links should open the correct images, since each call to
make_image_callback establishes up a separate context for a Proc inside
to capture, rather than all the Procs sharing the same context and
variables.

You could also do the call to link itself inside the helper method (as I
did in my earlier email), but you don't need to.

-mental

Reply via email to