开发者

Warning: already initialized constant JAVASCRIPT_DEFAULT_SOURCES

开发者 https://www.devze.com 2022-12-15 16:58 出处:网络
I switched from prototype library to jquery with jrails plugin. After that I\'ve got the warning: jrails.rb:17: warning: already initialized constant JAVASCRIPT_DEFAULT_SOURCES

I switched from prototype library to jquery with jrails plugin. After that I've got the warning:

jrails.rb:17: warning: already initialized constant JAVASCRIPT_DEFAULT_SOURCES

jrails.rb looks like:

ActionView::Helpers::PrototypeHelper::JQUERY_VAR = 'jQuery'
ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES = ['jquery.min', 'jquery-ui.min', 'jrails.min']
ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
ActionView::Helpers::AssetTagHelper.register_javascript_exp开发者_开发问答ansion :jquery => ['jquery.min', 'jquery-ui.min']

require 'jquery/jrails'

Where is constant JAVASCRIPT_DEFAULT_SOURCES initialize else? How can I fix this warning?


In jrails.rb you should remove (or comment) 2 lines with "default" and you can add 1 line for jrails:

ActionView::Helpers::PrototypeHelper::JQUERY_VAR = 'jQuery'
#ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES = ['jquery.min', 'jquery-ui.min', 'jrails.min']
#ActionView::Helpers::AssetTagHelper::reset_javascript_include_default
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jquery => ['jquery.min', 'jquery-ui.min']
ActionView::Helpers::AssetTagHelper.register_javascript_expansion :jrails => ['jrails.min']

require 'jquery/jrails'

In layouts replace default explicitly with jquery and jrails:

= javascript_include_tag :jquery
= javascript_include_tag :jrails

As advantageous this approach is even more descriptive.


It looks like ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES is also set in the jrails plugin in file /rails/init.rb.

Is the warning causing an issue in your application?

if you want to get rid of it you could just remove the reference in /rails/init.rb of the plugin or put an if around to check if the constant already exists.

I am looking at http://github.com/aaronchi/jrails/blob/master/rails/init.rb for this answer.


one of the purposes of jrails is to replace prototype, which is default in Rails 1.x and 2.x, through jQuery. For that reason the JAVASCRIPT_DEFAULT_SOURCES is overwritten. This is recognized by rails and leads to a warning. IT'S A FEATURE AND NOT A BUG.

I'm reworking compass-jquery-plugin these days to get from 'W.I.P' to 'released'. I'll add more AssetTagHelpers.

0

精彩评论

暂无评论...
验证码 换一张
取 消