views:

343

answers:

3

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?

A: 

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
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
Dave, actually I have got rid of it almost as you advised. Thanks!
Voldy
A: 

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
A: 

Hi Voidy,

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.

Cheers

Kosmas

Kosmas58