Hi, I''m not sure how to do this, can any body please help out ? In my controller i''m rendering a static file named ''myfile'' using rendering from the method named show ie def show render :file => ''C:/myfile'', :layout => true end Everything is fine, i''m able to see the myfiile getting rendered properly. But i want to insert a "JavaScript" dynamically into the rendered page. Something like this <%= javascript_include_tag "UtilitiesOn" %> ie. the above JavaScript "UtilitiesOn" is not originally part of the ''myfile'' Hence i want to include the above JS file dynamically either from controller or view helper is it possible to do? Thanks and Regards Dinesh -- 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 -~----------~----~----~----~------~----~------~--~---
Dinesh Umanath wrote:> def show > render :file => ''C:/myfile'', :layout => true > end> Something like this > <%= javascript_include_tag "UtilitiesOn" %> > > Hence i want to include the above JS file dynamically either from > controller or view helper is it possible to do?how about: 1. using several layout files, and every layout includes a different js file. 2. using controller to specify wanted layout. -- 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 -~----------~----~----~----~------~----~------~--~---
Hi Zhan, Thanks for the reply. Yesterday i was trying out the whole day to find out a way to do, but i could not do, finally i created a "newLayout" and included this JS. The "newLayout" differs from the "MasterLayout" with just this JS inclusion in the "newLayout" (Its great that your idea is coincidence with the way/workaround that i finally made and i''m certainly glad about it) It worked well.. But the problem in long term perspective is that say if we do some chagnes to the "MasterLayout" say added few more links, then we have to make sure that we replicate these changes to the "newLayout" also. So at anytime we may have to maintain two copies of the "Layout" with one the Js inclusion and the other without it. and i guess this is an overhead. Another workaround is that just before rendering the HTML file from the controller, use the File IO to read the HTML file and append the <script> <%= javascript_include_tag "UtilitiesOn" %> </script>.and this also worked, This way we do not need the "newLayout". But the problem here is every time we do a refresh the above <script> .. </script> gets appended to the HTML file and finally multiple <script> ..</script> entries are found in the HTML file. As we know there is no harm evern though when we use multiple same <script> .. </script>..but it does look good though rt? if anybody looks at the HTML file.. But since i could not find a way or know how to do it, i''m currently using the "newlayout" workaround. Any other ways ? Thanks Dinesh. -- 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 1/19/07, Dinesh Umanath <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi Zhan, > > Thanks for the reply. > > Yesterday i was trying out the whole day to find out a way to do, but i > could not do, finally i created a "newLayout" and included this JS. The > "newLayout" differs from the "MasterLayout" with just this JS inclusion > in the "newLayout" > (Its great that your idea is coincidence with the way/workaround that i > finally made and i''m certainly glad about it) > > It worked well.. > > But the problem in long term perspective is that say if we do some > chagnes to the "MasterLayout" say added few more links, then we have to > make sure that we replicate these changes to the "newLayout" also. So at > anytime we may have to maintain two copies of the "Layout" with one the > Js inclusion and the other without it. and i guess this is an overhead. > > > Another workaround is that just before rendering the HTML file from the > controller, use the File IO to read the HTML file and append the > <script> <%= javascript_include_tag "UtilitiesOn" %> </script>.and this > also worked, This way we do not need the "newLayout". But the problem > here is every time we do a refresh the above <script> .. </script> gets > appended to the HTML file and finally multiple <script> ..</script> > entries are found in the HTML file. As we know there is no harm evern > though when we use multiple same <script> .. </script>..but it does look > good though rt? if anybody looks at the HTML file.. > > > But since i could not find a way or know how to do it, i''m currently > using the "newlayout" workaround. Any other ways ? > > Thanks > Dinesh. > > > > > -- > Posted via http://www.ruby-forum.com/. > > > >I have written a plugin that may help you. I''m not sure that I completely understand what you want to do though. But it may help. http://www.agilewebdevelopment.com/plugins/resource_on_demand --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Dinesh Umanath wrote:> But since i could not find a way or know how to do it, i''m currently > using the "newlayout" workaround. Any other ways ?Could you use the same layout file but add a conditional include of a partial ? (said partial just containing the javascript_include tag). 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 -~----------~----~----~----~------~----~------~--~---
Hi Francis, Thanks for the reply. Basically i''m rendering a "file" like this. render :file => filename, :layout => "newLayout" I tried to use partials, but no luck. I guess we cannot use the :file => filename when we use :partial Dinesh Alan Francis wrote:> Dinesh Umanath wrote: > >> But since i could not find a way or know how to do it, i''m currently >> using the "newlayout" workaround. Any other ways ? > > Could you use the same layout file but add a conditional include of a > partial ? (said partial just containing the javascript_include tag). > > 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 -~----------~----~----~----~------~----~------~--~---
Dinesh Umanath wrote:> Hi Francis, > > Thanks for the reply. > > Basically i''m rendering a "file" like this. > > render :file => filename, :layout => "newLayout" > > > I tried to use partials, but no luck. > > I guess we cannot use the :file => filename when we use :partial > > Dinesh >In your newLayout.rhtml file you can have: <%= render :partial => ''common/javascript_1'' %> which will render whatever is in the file app/views/common/_javascript_1.rhtml. This could happily be javascript. -- 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 -~----------~----~----~----~------~----~------~--~---
Hi askegg, I agree with you that when we do like this <%= render :partial => ''common/javascript_1'' %> which will render whatever is in the file app/views/common/_javascript_1.rhtml. But my requirement, the above ''javaScript'' file has to be appended(integrated) to the file which i''m rendering. As shown in the below example, ''filename'' is the actual file which i want to render, Add-on to that i also want to dynamically include a "JavaScript" when the ''filename'' is rendered. In other words the ''filename'' is a static file and the ''JavaScript'' will not be included in that ''filename''. I want to include the ''JavaScript'' from the controller into the ''filename'' when it gets rendered from the browser. ie This "JavaScript" is NOT part of the initial static ''filename''. From the Controller based on some conditions i want to include different JS into the static file name, so that finally the filename and JS is integrated and rendered in the browser. Thanks a LOT Dinesh -- 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 -~----------~----~----~----~------~----~------~--~---
>From what I read of the API this is not possible as "render :file" istreated like "render :action", but without the layout applied. Perhaps you could create a instance variable to read the file into, then append the javascript to it? I have not looked at file handling in Ruby yet, but it seems easy enough. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---