0

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?

Voldy
  • 12,829
  • 8
  • 51
  • 67

3 Answers3

1

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.

Voldy
  • 12,829
  • 8
  • 51
  • 67
0

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.

dave elkins
  • 331
  • 2
  • 4
  • This warning doesn't cause an issue in application, but it comes up when I run Mongrel or script/generate. I don't like warnings. Actually I use http://github.com/kosmas58/compass-jquery-plugin and it really has this declaration in src/jrails/config/initializers/jrails.rb, but as I see it is only source. I've tried to comment all declarations of JAVASCRIPT_DEFAULT_SOURCES exept one in my_app/config/initializers/jrails.rb. Nothing changed. If I comment it in my_app/config/initializers/jrails.rb javascript default doesn't reset. – Voldy Jan 08 '10 at 19:27
  • Dave, actually I have got rid of it almost as you advised. Thanks! – Voldy Feb 19 '10 at 13:33
0

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.

j0k
  • 22,600
  • 28
  • 79
  • 90