Not sure what''s going on here but the js is printing out on the page along with what should be rendered. I have an index page, so in the helper, I created this function: module IndexHelper def menu render :update do |page| page.insert_html :bottom, ''subnav'' , :partial => ''navigation'' end end end Then in the layout page: <div id="subnav"> <%= menu %> </div> Finally in the navigation partial: <% if current_user.level = 1 %> <h2>Navigation for Company</h2> <% elsif current_user.level = 2 %> <h2>Navigation for User</h2> <% end %> Yet , what is getting printed on the page is : try { new Insertion.Bottom("subnav", "\n Navigation for Company \n\n\n"); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''new Insertion.Bottom(\"subnav\", \"\n Navigation for Company\n\n\n\");''); throw e } So, one thing is it''s spitting back the right text but twice, then I don''t understand why the js is printing out. TIA Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That''s what render :update does : it produces javascript. Did you want to just render :partial => ''navigation'' ? Fred -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
On 11/20/06, Frederick Cheung <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > That''s what render :update does : it produces javascript. > Did you want to just render :partial => ''navigation'' ? > > FredI guess. I don''t understand why there would be a rendering of the js to the page. So, then yes I would jsut want to render the partial. Stuart --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
n 11/20/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 11/20/06, Frederick Cheung <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > > That''s what render :update does : it produces javascript. > > Did you want to just render :partial => ''navigation'' ? > > > > Fred > >I want the insert_html to update the div . Stuart --~--~---------~--~----~------------~-------~--~----~ 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 11/20/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Not sure what''s going on here but the js is printing out on the page along > with what should be rendered. > > I have an index page, so in the helper, I created this function: > > module IndexHelper > def menu > render :update do |page| > page.insert_html :bottom, ''subnav'' , :partial => ''navigation'' > end > end > end > > Then in the layout page: > <div id="subnav"> > <%= menu %> > </div> > > Finally in the navigation partial: > <% if current_user.level = 1 %> > <h2>Navigation for Company</h2> > <% elsif current_user.level = 2 %> > <h2>Navigation for User</h2> > <% end %> > > Yet , what is getting printed on the page is : > > try { new Insertion.Bottom("subnav", "\n > Navigation for Company > \n\n\n"); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); > alert(''new Insertion.Bottom(\"subnav\", \"\n > Navigation for Company\n\n\n\");''); throw e } > > So, one thing is it''s spitting back the right text but twice, > then I don''t understand why the js is printing out.Should I not have the insert_html in the helper.rb file ? Stuart --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
insert_html is for producing a bunch of javascript that will insert some html. It''s most commonly used with rjs templates, although you could of course use it whenever you needed that javascript. There''s nothing wrong with having it in the helper file, but typically you don''t want it in a rhtml template (since it won''t be evaluated). So instead of callng insert_html ... You should just do the render itself in the right place. (ie if menu just does render :partial => ''navigation'' you should be ok Fred -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
I need the javascript becasue the page / layout doesn''t fully reload. What I can''t figure out is how to use a rjs template in this situation. Having it in the helper file seems to be the only way it works , yet for some reason, it''s rendering the lines of javascript to the screen along with what is intended to be shown. Stuart On 11/21/06, Frederick Cheung <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > insert_html is for producing a bunch of javascript that will insert some > html. It''s most commonly used with rjs templates, although you could of > course use it whenever you needed that javascript. > There''s nothing wrong with having it in the helper file, but typically > you don''t want it in a rhtml template (since it won''t be evaluated). So > instead of callng insert_html ... You should just do the render itself > in the right place. (ie if menu just does render :partial => > ''navigation'' you should be ok > > Fred > > -- > Posted via http://www.ruby-forum.com/. > > > >-- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
render :update and RJS templates do exactly this. They render JavaScript the brwoser has to evaluate ... but they dont apply any <script> tags because what they are intentionally meant for are AJAX calls. and that AJAX Object evaluates the JavaScript: If you use a RJS template in a helper, it wont be evaluated as there''s no AJAx Object to receive the JavaScript generated by the template. I still cant get a clear pitcure of what you actually trying to do (you say it doesn''t completely refresh ... spounds like AJAX ... where''s the AJAX call then?), sure render :partial won''t work? did you try it?>From your code, you only render a partial through some javascript, andthen insert that javascript in a div tag thorugh a helper... layout calls helper "menu" -> menu calls render :update > render :update call render :partial> partial gets rendered ... but IN JavaScript. why should this not work: layout calls helper "menu" -> menu calls render :partial -> partial gets render ... in HTML (which is what you want obviously ...) --~--~---------~--~----~------------~-------~--~----~ 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 11/21/06, Thorsten L <duplexxx-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > > render :update and RJS templates do exactly this. They render > JavaScript the brwoser has to evaluate ... > but they dont apply any <script> tags because what they are > intentionally meant for are AJAX calls. and that AJAX Object evaluates > the JavaScript: > > If you use a RJS template in a helper, it wont be evaluated as there''s > no AJAx Object to receive the JavaScript generated by the template. > > I still cant get a clear pitcure of what you actually trying to do (you > say it doesn''t completely refresh ... spounds like AJAX ... where''s the > AJAX call then?), sure render :partial won''t work? did you try it? > > >From your code, you only render a partial through some javascript, and > then insert that javascript in a div tag thorugh a helper... > > layout calls helper "menu" -> menu calls render :update > render > :update call render :partial> partial gets rendered ... but IN > JavaScript. > > why should this not work: > layout calls helper "menu" -> menu calls render :partial -> partial > gets render ... in HTML (which is what you want obviously ...)Okay, I got this working without any javascript / Ajax calls. Just rendering the navigation partial is fine. Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Stuart Fellowes wrote:> Okay, I got this working without any javascript / Ajax calls. Just > rendering the navigation partial is fine. > > StuartI think I understand what you''re trying to do but, as was noted earlier, I think you may be mixing up two types of operation. 1) calling the helper from within your rhtml is evaluated when the whole page is reloaded. The helper called render :update, which just returns a big string of javascript. Thats treated as HTML text and is compiled into your page. 2) using RJS to update the page. From within the RHTML, use prototype to trigger an ajax call to some action. That action would call render :update (and the insert_html etc). That would return a big string of javascript back to prototype, which would evaluate it (thus inserting the html). You can think of 1) as html-page-compile-time and 2) as html-page-run-time. render :partial returns html which is included at compile time. render :update returns javascript which is executed at runtime. Since helpers are ''compile-time'' you need to use partials and not updates Does this help at all ? A. -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Hey Alan, that pretty much sums up very nicely what i tried to say with my whacky english :D Nice Explanation indeed ... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten, my apologies for not replying sooner. Yes, your explanation helped. Stuart On 11/21/06, Thorsten L <duplexxx-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > > Hey Alan, that pretty much sums up very nicely what i tried to say with > my whacky english :D > > Nice Explanation indeed ... > > > > >-- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---