When you call javascript_include_tag :defaults
you usually get: prototype.js
, effects.js
, dragdrop.js
, and controls.js
.
These are stored in a constant in ActionView::Helpers::AssetTagHelper
called 'JAVASCRIPT_DEFAULT_SOURCES`. My application uses jQuery, so I want to replace the Prototype references with something more useful.
I added an initializer with these lines, based on the source code from jRails:
ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES = %w{ jquery-1.4.min jquery-ui jquery.cookie }
ActionView::Helpers:开发者_如何学运维:AssetTagHelper::reset_javascript_include_default
But when I do this, I get: warning: already initialized constant JAVASCRIPT_DEFAULT_SOURCES
during startup.
What's the correct way of changing this value? In the source code it checks for the constant before setting it, but apparently that happens before it runs the initializer scripts.
The Rails 3.0 release will provide much greater flexibility with choice of JS libraries, so I guess this is a problem with an expiration date.
Why not just do something like this?
<%= javascript_include_tag "jquery-1.4.min", "jquery-ui", "jquery.cookie" %>
You dont need to use the ":defaults" option. Take at look at:
http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#M001713
According to this thread on ruby-forum, you can't. Although, if you look here, there are a few .diff files that you could grab that would at least let you do something like this:
# environment.rb
ActionView::Helpers::AssetTagHelper::register_javascript_expansion :monkey, "head", "body", "tail"
ActionView::Helpers::AssetTagHelper::register_stylesheet_expansion :monkey, "head", "body", "tail"
# your .erb/.haml files
javascript_include_tag :monkey
stylesheet_link_tag :monkey
I know this obviously doesn't help you do what you're trying to do, but hopefully it at least helps point you in a positive direction.
精彩评论