hey, new to RoR. I''m having great success implementing Jack Slocum''s yui-ext (www.jackslocum.com) with RoR. but how can I dynamically include a controller-specific library into the html head? I''d like to be able to do this: [code] InventoryController < ApplicationController def index self.register_javascript(''application/inventory/InventoryManager'') end end [/code] -- 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 -~----------~----~----~----~------~----~------~--~---
Chris, I am new to all this as well and haven''t really written anything in RoR yet, so hopefully this is the correct way to do it, and if not hopefully someone will correct me. in your controller, use before_filter to define an instance variable: before_filter :include protected def include @jsinclude = ''something.js'' end Then in the application.rhtml file: <% if @jsinclude %><%= javascript_include_tag @jsinclude %><% end %> My only concern is if I did the if @jsinclude statement correctly as "unless @jsinclude.empty?" throws an exception when a view is called under another controller. -- 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 -~----------~----~----~----~------~----~------~--~---
Jodi Showers
2007-Feb-21 16:40 UTC
Re: how to include a controller-specific javascript library
On 21-Feb-07, at 11:33 AM, Tim W. wrote:> > Chris, > > I am new to all this as well and haven''t really written anything in > RoR > yet, so hopefully this is the correct way to do it, and if not > hopefully > someone will correct me. > > in your controller, use before_filter to define an instance variable: > > > before_filter :include > > protected > def include > @jsinclude = ''something.js'' > end > > > Then in the application.rhtml file: > > <% if @jsinclude %><%= javascript_include_tag @jsinclude %><% end %> > > My only concern is if I did the if @jsinclude statement correctly as > "unless @jsinclude.empty?" throws an exception when a view is called > under another controller.although that solution is technical feasible, mvc encourages us to separate concerns. This is a view concern, and as such the controller "shouldn''t" be concerned. why not use the layout for this controller? Jodi --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jodi Showers wrote:> why not use the layout for this controller?That makes sense. So now since application.rhtml is not used, the best practice would be to create partials for the header and footer information that was previously displayed via application.rhtml ? -- 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 Feb 21, 11:58 am, "Tim W." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Jodi Showers wrote: > > why not use the layout for this controller? > > That makes sense. > > So now since application.rhtml is not used, the best practice would be > to create partials for the header and footer information that was > previously displayed via application.rhtml ? > > -- > Posted viahttp://www.ruby-forum.com/.or you could have the application layout check the controller name, and return the JS include. This is probably a good use for a helper - < %= get_JS(controller.controller_name) %> I''d likely tackle by that means - the application helper might even have scope to access the controller object, so your call would just be "get_JS" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Scott
2007-Feb-21 17:33 UTC
Re: how to include a controller-specific javascript library
> mvc encourages us to > separate concerns. This is a view concern, and as such the controller > "shouldn''t" be concerned.I don''t think it''s correct to write-off javascript simply as "view" concern. the javascript lib I wish to include *is* a controller and has the same name as the rails controller. it''s like a client-side agent of the controller. eg: InventoryController.rb < ApplicationController ... InventoryController.js -- 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 -~----------~----~----~----~------~----~------~--~---
Chris Scott
2007-Feb-21 21:54 UTC
Re: how to include a controller-specific javascript library
> I''d likely tackle by that means - the application helper might even > have scope to access the controller object, so your call would just be > "get_JS"cheers. that''ll work. -- 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 -~----------~----~----~----~------~----~------~--~---
Daniel N
2007-Feb-21 21:56 UTC
Re: how to include a controller-specific javascript library
On 2/22/07, Chris Scott <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > > mvc encourages us to > > separate concerns. This is a view concern, and as such the controller > > "shouldn''t" be concerned. > > I don''t think it''s correct to write-off javascript simply as "view" > concern. > > the javascript lib I wish to include *is* a controller and has the same > name as the rails controller. it''s like a client-side agent of the > controller. > > eg: > InventoryController.rb < ApplicationController > > ... > > InventoryController.jsI wrote a plugin a while ago just for this. You can find details for it at http://www.agilewebdevelopment.com/plugins/resource_on_demand Hopefully it will do what you''re after --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Chris Scott
2007-Feb-21 23:29 UTC
Re: how to include a controller-specific javascript library
> Hopefully it will do what you''re afterexactly. ensures no duplicates. perfect, thanks. -- 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 usually just build up an array within my controller such as: @javascript_includes = [''prototype'',''scriptaculous'',''other_file''] and then in my layout have: <%=javascript_include_tag *@javascript_includes -%> Regards, Glenn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---