Hi, I''ve just been testing update_element_function in combination with form_remote_tag and :complete => evaluate_response_text. I initially created an action (called test) that had one line.. render :text => "alert(''hello'')" In the view that was calling this action I had <%= form_remote_tag :url => { :action => ''test'' }, :complete => evaluate_response_text %> I submitted the form and the test action was called which returned the text above. This was eval''d and an alert was displayed. All good. The next thing was to amend the action to output an update_element_function call. I had the following. render :text => "update_element_function(''mydiv'', :action => :update, :position => :bottom, :content => ''hello world 123'')" This didn''t work. I added a link_to_function in the view calling exactly the same line as above (without the render) and ''hello world 123'' was added to the bottom of ''mydiv'' as expected. I tried a few other things but finally got round to placing the ''update_element...'' call in a view of it''s own. I created the ''test'' view and added the following. <%= update_element_function( ''mydiv'', :action => :update, :position => :bottom, :content => ''hello world 123'') %> I removed the render call from the test action and now I get the results I expect, i.e. the ''hello world 123'' string is appended to the bottom of ''mydiv''. My question is, why does this work when called from a view but not directly output using render :text (yet a simple js alert does) from the action? NB. I also tried wrapping the ''update_element...'' call in a javascript_tag when passing to the render method but still to no avail. Chris
Chris Roos wrote:> Hi, > > I''ve just been testing update_element_function in combination with > form_remote_tag and :complete => evaluate_response_text. > > I initially created an action (called test) that had one line.. > > render :text => "alert(''hello'')" > > In the view that was calling this action I had > > <%= form_remote_tag :url => { :action => ''test'' }, :complete => > evaluate_response_text %> > > I submitted the form and the test action was called which returned the > text above. This was eval''d and an alert was displayed. All good. > > The next thing was to amend the action to output an > update_element_function call. I had the following. > > render :text => "update_element_function(''mydiv'', :action => :update, > :position => :bottom, :content => ''hello world 123'')" > > This didn''t work. I added a link_to_function in the view calling > exactly the same line as above (without the render) and ''hello world > 123'' was added to the bottom of ''mydiv'' as expected. > > I tried a few other things but finally got round to placing the > ''update_element...'' call in a view of it''s own. I created the ''test'' > view and added the following. > > <%= update_element_function( > ''mydiv'', > :action => :update, > :position => :bottom, > :content => ''hello world 123'') %> > > I removed the render call from the test action and now I get the results > I expect, i.e. the ''hello world 123'' string is appended to the bottom of > ''mydiv''. > > My question is, why does this work when called from a view but not > directly output using render :text (yet a simple js alert does) from the > action? > > NB. I also tried wrapping the ''update_element...'' call in a > javascript_tag when passing to the render method but still to no avail. > > Chris >On the off chance someone else is as stoopid as I am, I thought I''d reply as to why it doesn''t work. When the update_element_function helper is called in the view, it returns the value of the method, i.e. an actual javascript statement. When I rendered the same item as text from the controller, it doesn''t actually call update_element_function and therefore passes the text exactly as it stands, i.e. very much not a valid javascript statement. Chris
render :text => "update_element_function ... will render the string exactly as given, whereas render :inline => "<%= update_element_function ... will execute inline template instructions (think of a .rhtml file in a string). See also http://raildock.mytechsupport.com/ri/ ActionController::Base@render Am 26.07.2005 um 18:04 schrieb Chris Roos:> Chris Roos wrote: > >> Hi, >> I''ve just been testing update_element_function in combination with >> form_remote_tag and :complete => evaluate_response_text. >> I initially created an action (called test) that had one line.. >> render :text => "alert(''hello'')" >> In the view that was calling this action I had >> <%= form_remote_tag :url => { :action => ''test'' }, :complete => >> evaluate_response_text %> >> I submitted the form and the test action was called which returned >> the text above. This was eval''d and an alert was displayed. All >> good. >> The next thing was to amend the action to output an >> update_element_function call. I had the following. >> render :text => "update_element_function(''mydiv'', :action >> => :update, :position => :bottom, :content => ''hello world 123'')" >> This didn''t work. I added a link_to_function in the view calling >> exactly the same line as above (without the render) and ''hello >> world 123'' was added to the bottom of ''mydiv'' as expected. >> I tried a few other things but finally got round to placing the >> ''update_element...'' call in a view of it''s own. I created the >> ''test'' view and added the following. >> <%= update_element_function( >> ''mydiv'', >> :action => :update, >> :position => :bottom, >> :content => ''hello world 123'') %> >> I removed the render call from the test action and now I get the >> results I expect, i.e. the ''hello world 123'' string is appended to >> the bottom of ''mydiv''. >> My question is, why does this work when called from a view but not >> directly output using render :text (yet a simple js alert does) >> from the action? >> NB. I also tried wrapping the ''update_element...'' call in a >> javascript_tag when passing to the render method but still to no >> avail. >> Chris >> > On the off chance someone else is as stoopid as I am, I thought I''d > reply as to why it doesn''t work. When the update_element_function > helper is called in the view, it returns the value of the method, > i.e. an actual javascript statement. When I rendered the same item > as text from the controller, it doesn''t actually call > update_element_function and therefore passes the text exactly as it > stands, i.e. very much not a valid javascript statement. > > Chris > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >