警告:已初始化常量 JAVASCRIPT_DEFAULT_SOURCES
我从原型库切换到带有 jrails 插件的 jquery。之后我收到警告:
jrails.rb:17: warning: already initialized constant JAVASCRIPT_DEFAULT_SOURCES
jrails.rb 看起来像:
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']
require 'jquery/jrails'
常量 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_expansion :jquery => ['jquery.min', 'jquery-ui.min']
require 'jquery/jrails'
Where is constant JAVASCRIPT_DEFAULT_SOURCES initialize else? How can I fix this warning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 jrails.rb 中,您应该删除(或注释)带有“default”的 2 行,并且可以为 jrails 添加 1 行:
在布局中,用 jquery 和 jrails 显式替换 default:
这种方法更有利描述性的。
In jrails.rb you should remove (or comment) 2 lines with "default" and you can add 1 line for jrails:
In layouts replace default explicitly with jquery and jrails:
As advantageous this approach is even more descriptive.
看起来 ActionView::Helpers::AssetTagHelper::JAVASCRIPT_DEFAULT_SOURCES 也在文件 /rails/init.rb 的 jrails 插件中设置。
该警告是否导致您的应用程序出现问题?
如果你想摆脱它,你可以删除插件的 /rails/init.rb 中的引用,或者放置一个 if 来检查常量是否已经存在。
我正在查看 http://github.com/aaronchi/jrails/ blob/master/rails/init.rb 获取此答案。
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.
jrails 的目的之一是通过 jQuery 替换 Rails 1.x 和 2.x 中默认的原型。因此,
JAVASCRIPT_DEFAULT_SOURCES
被覆盖。这会被 Rails 识别并发出警告。这是一个功能,而不是一个错误。这些天我正在重新设计 compass-jquery-plugin,以从“WIP”变为“已发布”。我将添加更多 AssetTagHelpers。
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.