Jonathan del Strother
2006-Sep-13 11:47 UTC
Detecting whether response.body is html / javascript?
I''ve got an after_filter which adds code to response.body for popping up a flash - it''s kinda handy for having flash messages appear automatically with each ajax request, without having to explicitly include the flash code in every single action... However, I''m running into problems with detecting whether I''m returning js or html. If I''m using an rjs, then I can just add the javascript code on the end. If I''m using a partial, then I need to wrap it in script tags. But I can''t figure out how to detect which one I should be using. Is there any way for my controller to detect whether the response is going to be executed (js) or just inserted (html)? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Bill Walton
2006-Sep-13 12:21 UTC
Re: Detecting whether response.body is html / javascript?
Hi Jonathan, Jonathan del Strother wrote:> I''m running into problems with detecting whether > I''m returning js or html.Check out the respond_to method. A word or caution... there''s a bug that precludes the use of '':disable_with'' if you''re using a form_remote_tag to initiate the server-side action. There''s a recent thread where I was having a problem with respond_to and a couple of Railers pointed it out to me. hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jonathan del Strother
2006-Sep-13 12:40 UTC
Re: Detecting whether response.body is html / javascript?
On 13 Sep 2006, at 13:21, Bill Walton wrote:> Hi Jonathan, > > Jonathan del Strother wrote: > >> I''m running into problems with detecting whether >> I''m returning js or html. > > Check out the respond_to method. A word or caution... there''s a > bug that > precludes the use of '':disable_with'' if you''re using a > form_remote_tag to > initiate the server-side action. There''s a recent thread where I > was having > a problem with respond_to and a couple of Railers pointed it out to > me.Mmm, re-reading my email, I wasn''t very clear - I''m already using respond_to to only insert the flash popup into ajax-y responses. My problem boils down to figuring out whether I''m using Ajax.Updater or Ajax.Request. Looking at the prototype code, I''m not so convinced that this is possible on the server side. Maybe I could modify Ajax.Updater to add a parameter I could detect on the server... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I eventually got around it by tweaking prototype.js to send the expected return type in the headers. Seems to work ok, though I''d be interested in any alternate solutions --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---