I have the following helper (see below) with two calls to observe_field. In the viewer, the helper is used according to:

  <%= observe_slider 'time', 0.1, 'display_full_size', "slider_val", u[1] %>

Only the second call to observe_field is acted up. If I invert the order of the calls in the helper, then it is still the second call to observe_field that works. It is as if the second call was overwriting the first. I found a similar behavior in the viewer before using the helper. If I wrapped each call to observe_field in <%= %> tags, they both worked. However, if I wrapped both calls into a single <%= %>, only the second one worked. Does any on of you have any ideas?



i believe because observe_field writes to the output stream, you need to capture its output like

  def observe_slider(id, freq, img_id, local_var, url)     # :idd variable name is hardcoded. Should not be.     str = observe_field( "#{id}_h",        :frequency => freq,        :update => "#{img_id}_hide",        :with => local_var,        :complete => "update_time(request)",        :url => { :action => "#{img_id}", :idd => url })

    str << observe_field( "#{id}",          :update => "#{img_id}_hide",          :with => local_var,          :complete => 'update_time(request)',        :url => { :action => "#{img_id}", :idd => url } )     return str   end

I think you're on the right track. The issue appears to be that the helper is just like any other method call -- you're going to receive back whatever the method returns and it's results are then going to be added to the page. In the original code the return value, since it's not explicitly stated, will be the result of the last method call which is always the last observe_field call. That's why it appears that the last call is "overwriting" the previous call(s).

@jemminger's recommendation will work because observe_field will return a string and when you concat the strings you can return the cumulative result and then render that into the page.


Thanks guys. The suggestion worked!