ruby on rails - loading order JavaScript files in asset pipeline - Stack Overflow

I am using a Rails 4 application. I installed some JavaScript plugin files in "vendorassetsjavas

I am using a Rails 4 application. I installed some JavaScript plugin files in "vendor/assets/javascripts", and some in "app/assets/javascripts" where I have some files that are invoking methods from the vendor files.

No methods from these are recognized and it seems that "app/assets/javascripts" files are loaded before "vendor/assets/javascripts" files. How can I deal with that?

For information my "application.js" calls:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require rails.validations
//= require_tree .

and I am using gem 'jquery-rails'.

I am using a Rails 4 application. I installed some JavaScript plugin files in "vendor/assets/javascripts", and some in "app/assets/javascripts" where I have some files that are invoking methods from the vendor files.

No methods from these are recognized and it seems that "app/assets/javascripts" files are loaded before "vendor/assets/javascripts" files. How can I deal with that?

For information my "application.js" calls:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require rails.validations
//= require_tree .

and I am using gem 'jquery-rails'.

Share Improve this question edited Feb 21, 2014 at 17:35 the Tin Man 161k44 gold badges221 silver badges306 bronze badges asked Feb 21, 2014 at 16:29 epsilonesepsilones 11.6k22 gold badges65 silver badges89 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

Any files in your vendor tree that you need must be required explicitly in your "application.js". It will pull in all the JavaScript in your "app/assets/" tree using the "require_tree".

You probably need to update your file to look something more like this:

//= require jquery
//= require jquery_ujs 
//= require turbolinks
//= require rails.validations
//= require that_file_from_vendor_assets
//= require that_other_file_from_vendor_assets
//= require_tree .

where that_file_from_vendor_assets is the vendor JavaScript that you need to be loaded up before it gets to your "app/assets/javascript" files.

Just change

//=require_tree .

like this:

//= require_self

Then files will be imported in the order of you put them to your application.js file.

And don't forget <%= javascript_include_tag "application"%> in your layout file.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742399505a4436624.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信