List Info

Thread: Automatically loading controller-specifc JS




Automatically loading controller-specifc JS
country flaguser name
United States
2008-01-01 07:09:05
There was a thread recently that brought up the idea of
modifying  
javascript_include_tag to load a controller-specific js file
 
automatically.  I took a look at doing that last night, and 

discovered that it's actually quite a simple thing to do
without  
extending the Rails source.  In a layout, all you have to do
is:

	<%= javascript_include_tag params[:controller] if
File.exists?("# 
/public/javascripts/#{params[:controller]}.js&qu
ot;) %>

Admittedly, this is not DRY because you would need to do
this for  
every application you write. But it is DRY for the current
application.

Just thought I'd pass that along.

Peace,
Phillip

--~--~---------~--~----~------------~-------~--~----~
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-talkgooglegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )