I got a short question about RJS. Is it possible to get the RJS to "compile" to Javascript code without having to use AJAX? As in, can I use RJS to bundle some javascript code with my page when it''s first created? Thanks, Mathias Wittlock. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can use all the helpers you use in a RJS template in a vie as well, you just dont need the page obejct. you can also use the JavaScript Helpers to create script tags, links with function calls etc.for this. link_to_function "hide menu", visual_effect(:fade, "menu") On 12 Feb., 13:15, "Mathias Wittlock" <wittlock +rubyonrailsl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I got a short question about RJS. > > Is it possible to get the RJS to "compile" to Javascript code without > having to use AJAX? As in, can I use RJS to bundle some javascript > code with my page when it''s first created? > > Thanks, > Mathias Wittlock.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2/12/07, Thorsten L <duplexxx-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > You can use all the helpers you use in a RJS template in a vie as > well, you just dont need the page obejct. > you can also use the JavaScript Helpers to create script tags, links > with function calls etc.for this. > > link_to_function "hide menu", visual_effect(:fade, "menu")Hmm, this pointed me in the right direction to get what I wanted. Thanks a bunch, much appreciated! :) Mathias. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2/12/07, Mathias Wittlock <wittlock+rubyonrailslist-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I got a short question about RJS. > > Is it possible to get the RJS to "compile" to Javascript code without > having to use AJAX? As in, can I use RJS to bundle some javascript > code with my page when it''s first created? >Thorsten gave you one answer---probably the one you wanted. Another answer is simply "yes". You can use te JavaScriptGenerator which RJS invokes in any view context (or instantiate it manually if you want to go through those pains). Here''s what it looks like: update_page do |page| page[''an-element''].visual_effect :shake end This block will actually return the generated Javascript. So, for example, if you wanted to do your own special link_to_shake helper, you could do something like this (untested): def link_to_shake(element_id) link_to_function "Shake it", update_page do |page| page[element_id].visual_effect :shake end end Chad --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
igotimac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Feb-12 15:03 UTC
Re: Quick RJS question.
This could be usefull in debugging RJS output for those of us that have no clue about RJS and want to see the javascript it''s generating... If I were writting normal javascript I would do: $(''attribute[<%=index%>][id_to_me]'').value = ""; $(''filename- <%=index%>'').value = ""; but I want to return javascript as an Ajax response so I''m doing: page.select("#attribute[#{index}][id_to_me]").value = ""; page.select("#filename-#{index}").value = ""; And it''s not working, and I''m not really sure how to debug it. On Feb 12, 9:39 am, "Chad Fowler" <c...-Vm8wfZGX7qC+XT7JhA+gdA@public.gmane.org> wrote:> On 2/12/07, Mathias Wittlock <wittlock+rubyonrailsl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I got a short question about RJS. > > > Is it possible to get the RJS to "compile" to Javascript code without > > having to use AJAX? As in, can I use RJS to bundle some javascript > > code with my page when it''s first created? > > Thorsten gave you one answer---probably the one you wanted. Another > answer is simply "yes". You can use te JavaScriptGenerator which RJS > invokes in any view context (or instantiate it manually if you want to > go through those pains). Here''s what it looks like: > > update_page do |page| > page[''an-element''].visual_effect :shake > end > > This block will actually return the generated Javascript. So, for > example, if you wanted to do your own special link_to_shake helper, > you could do something like this (untested): > > def link_to_shake(element_id) > link_to_function "Shake it", update_page do |page| > page[element_id].visual_effect :shake > end > end > > Chad--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> page.select("#attribute[#{index}][id_to_me]").value = ""; > page.select("#filename-#{index}").value = "";you don''t use the # at the start of the id''s name in RJS, simply because it''s not used in Prototype Javascript as well. page.select("attribute[#{index}][id_to_me]").value = ""; page.select("filename-#{index}").value = ""; --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 2/12/07, igotimac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <igotimac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > This could be usefull in debugging RJS output for those of us that > have no clue about RJS and want to see the javascript it''s > generating... > > If I were writting normal javascript I would do: > > $(''attribute[<%=index%>][id_to_me]'').value = ""; > $(''filename- <%=index%>'').value = ""; > > but I want to return javascript as an Ajax response so I''m doing: > > page.select("#attribute[#{index}][id_to_me]").value = ""; > page.select("#filename-#{index}").value = ""; > > And it''s not working, and I''m not really sure how to debug it. >The best way is to use FireFox with FireBug. You can inspect the response of an XMLHTTPRequest and see the generated Javascript. Very handy. Chad --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---