Greetings Having the darndest time trying to render an inline RJS page element in my index page. I don''t have any trouble linking to a remote page and rendering RJS, but it''s got me stumped how to do it from the index page. I guess I have a basic gap in my understanding of how RJS works. A simple example would be to render page.alert(''hello world!'') when the user opens a support index page: http://example.com/support where the support controller action index is: def index render :update do |page| page.alert(''hello world!'') end end Which dumps raw Javascript to the web page: try { alert("hello world!"); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''alert(\"hello world!\");''); throw e } Thanks for the help! Dave --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi -- On 3/11/07, Dave <dfdumaresq-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Greetings > > Having the darndest time trying to render an inline RJS page element > in my index page. I don''t have any trouble linking to a remote page > and rendering RJS, but it''s got me stumped how to do it from the index > page. I guess I have a basic gap in my understanding of how RJS works. > > A simple example would be to render page.alert(''hello world!'') when > the user opens a support index page: > > http://example.com/support > > where the support controller action index is: > > def index > render :update do |page| > page.alert(''hello world!'') > end > end > > Which dumps raw Javascript to the web page: > > try { > alert("hello world!"); > } catch (e) { alert(''RJS error:\n\n'' + e.toString()); > alert(''alert(\"hello world!\");''); throw e }The usual cause of this is that you have an :update parameter in your view, so it updates the element with the raw javascript. David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> A simple example would be to render page.alert(''hello world!'') when > the user opens a support index page: >The way RJS works (notice is an abstraction, so no details given) is something like this. You already have a document loaded in your browser, and from this document you make a remote request, which will basically invoke a browser-side object capable of calling the remote point and, after getting a response, it will execute the remote response against your javascript document object. This means the entry point for a RJS to work is having a document in which to apply the changes. That document is what rails gives you in the "page" object. If you directly call a RJS action, what you get is the javascript that would execute against your document object. Since you don''t have any and you are not even in javascript context, you get just the plain text in your browser. That''s the reason many RJS actions have something like "return unless request.xhr?" meaning something like "do nothing unless we are being called via ajax" Regards, javier ramirez -- -------- Estamos de estreno... si necesitas llevar el control de tus gastos visita http://www.gastosgem.com !!Es gratis!! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi -- On 3/11/07, David A. Black <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> The usual cause of this is that you have an :update parameter in your > view, so it updates the element with the raw javascript.Well, technically my statement is correct -- that is the usual cause -- but in this case, see Javier''s answer rather than mine :-) David -- Q. What is THE Ruby book for Rails developers? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) (See what readers are saying! http://www.rubypal.com/r4rrevs.pdf) Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Very good. Now I understand why the Javascript is not getting rendered. I suppose wrapping script tags around the output will force it to render, but then I should be using erb, which is a little ugly, but works. What I''m after is calling a Javascript object within the view from the index page, so that no further clicks are needed. Using erb should do it. Thanks for the help! Dave On Mar 11, 8:04 am, javier ramirez <jrami...-7iWCczGtl7hBDgjK7y7TUQ@public.gmane.org> wrote:> > A simple example would be to render page.alert(''hello world!'') when > > the user opens a support index page: > > The way RJS works (notice is an abstraction, so no details given) is > something like this. You already have a document loaded in your browser, > and from this document you make a remote request, which will basically > invoke a browser-side object capable of calling the remote point and, > after getting a response, it will execute the remote response against > your javascript document object. > > This means the entry point for a RJS to work is having a document in > which to apply the changes. That document is what rails gives you in the > "page" object. > > If you directly call a RJS action, what you get is the javascript that > would execute against your document object. Since you don''t have any and > you are not even in javascript context, you get just the plain text in > your browser. That''s the reason many RJS actions have something like > "return unless request.xhr?" meaning something like "do nothing unless > we are being called via ajax" > > Regards, > > javier ramirez > > -- > -------- > Estamos de estreno... si necesitas llevar el control de tus gastos visitahttp://www.gastosgem.com!!Es gratis!!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---