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? Thanks, Gordon ====================Helper: def observe_slider(id, freq, img_id, local_var, url) # :idd variable name is hardcoded. Should not be. observe_field( "#{id}_h", :frequency => freq, :update => "#{img_id}_hide", :with => local_var, :complete => "update_time(request)", :url => { :action => "#{img_id}", :idd => url }) # I cannot have two observe_field statements. The second one # seems to overwrite the first one. Do now know why # WHY, WHY!!! observe_field( "#{id}", :update => "#{img_id}_hide", :with => local_var, :complete => ''update_time(request)'', :url => { :action => "#{img_id}", :idd => url } ) end ================== --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Jul 24, 5:04 pm, gordon <erleb...-ZsLQZatIiLWVc3sceRu5cw@public.gmane.org> wrote:> 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? > > Thanks, > > Gordon > > ====================> Helper: > > def observe_slider(id, freq, img_id, local_var, url) > # :idd variable name is hardcoded. Should not be. > observe_field( "#{id}_h", > :frequency => freq, > :update => "#{img_id}_hide", > :with => local_var, > :complete => "update_time(request)", > :url => { :action => "#{img_id}", :idd => url }) > > # I cannot have two observe_field statements. The second one > # seems to overwrite the first one. Do now know why > # WHY, WHY!!! > > observe_field( "#{id}", > :update => "#{img_id}_hide", > :with => local_var, > :complete => ''update_time(request)'', > :url => { :action => "#{img_id}", :idd => url } ) > > end > ==================--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. AndyV On Jul 24, 9:18 pm, jemminger <jemmin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > On Jul 24, 5:04 pm, gordon <erleb...-ZsLQZatIiLWVc3sceRu5cw@public.gmane.org> wrote: > > > 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? > > > Thanks, > > > Gordon > > > ====================> > Helper: > > > def observe_slider(id, freq, img_id, local_var, url) > > # :idd variable name is hardcoded. Should not be. > > observe_field( "#{id}_h", > > :frequency => freq, > > :update => "#{img_id}_hide", > > :with => local_var, > > :complete => "update_time(request)", > > :url => { :action => "#{img_id}", :idd => url }) > > > # I cannot have two observe_field statements. The second one > > # seems to overwrite the first one. Do now know why > > # WHY, WHY!!! > > > observe_field( "#{id}", > > :update => "#{img_id}_hide", > > :with => local_var, > > :complete => ''update_time(request)'', > > :url => { :action => "#{img_id}", :idd => url } ) > > > end > > ==================--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks guys. The suggestion worked! Gordon On Jul 25, 12:58 pm, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> 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. > > AndyV > > On Jul 24, 9:18 pm, jemminger <jemmin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 > > > On Jul 24, 5:04 pm, gordon <erleb...-ZsLQZatIiLWVc3sceRu5cw@public.gmane.org> wrote: > > > > 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? > > > > Thanks, > > > > Gordon > > > > ====================> > > Helper: > > > > def observe_slider(id, freq, img_id, local_var, url) > > > # :idd variable name is hardcoded. Should not be. > > > observe_field( "#{id}_h", > > > :frequency => freq, > > > :update => "#{img_id}_hide", > > > :with => local_var, > > > :complete => "update_time(request)", > > > :url => { :action => "#{img_id}", :idd => url }) > > > > # I cannot have two observe_field statements. The second one > > > # seems to overwrite the first one. Do now know why > > > # WHY, WHY!!! > > > > observe_field( "#{id}", > > > :update => "#{img_id}_hide", > > > :with => local_var, > > > :complete => ''update_time(request)'', > > > :url => { :action => "#{img_id}", :idd => url } ) > > > > end > > > ==================--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---