1

(I'm new both to Rails and SO, so excuse if I'm not doing it right)

I am trying to adapt a regular third-party web template in my rails 4 application. I have a vendor folder with other files and subfolders like bootstrap.js, Nivo-slider and Isotope which contain both .css and .js files.

So I moved all files and subfolders to vendor/assets and included //= require_tree ../../../vendor/assets/ in my application.js, as recommended here. So my application.js looks like

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require turbolinks
//= require_tree ../../../vendor/assets/
//= require_tree .

And in my layout file:

<%=stylesheet_link_tag "application.css" -%>
<%=javascript_include_tag "application" -%> 

when I execute it on my server I get Sprockets::FileOutsidePaths exception:

Showing /home/valle/RoR/grifo/app/views/layouts/application.html.erb where line #25 raised: /home/valle/RoR/grifo/vendor/assets/bootstrap.js isn't in paths: /home/valle/RoR/grifo/app/assets/images, /home/valle/RoR/grifo/app/assets/javascripts, /home/valle/RoR/grifo/app/assets/stylesheets, /home/valle/RoR/grifo/lib/assets/circle-flip-slideshow, /home/valle/RoR/grifo/lib/assets/isotope, /home/valle/RoR/grifo/lib/assets/javascripts, /home/valle/RoR/grifo/lib/assets/jflickrfeed, /home/valle/RoR/grifo/lib/assets/magnific-popup, /home/valle/RoR/grifo/lib/assets/mediaelement, /home/valle/RoR/grifo/lib/assets/nivo-slider, /home/valle/RoR/grifo/lib/assets/owl-carousel, /home/valle/RoR/grifo/lib/assets/rs-plugin, /home/valle/RoR/grifo/lib/assets/stylesheets, /home/valle/RoR/grifo/lib/assets/twitterjs, /home/valle/.rvm/gems/ruby-1.9.3-p392/gems/modernizr-rails-2.7.1/vendor/assets/javascripts, /home/valle/.rvm/gems/ruby-1.9.3-p392/gems/turbolinks-2.2.2/lib/assets/javascripts, /home/valle/.rvm/gems/ruby-1.9.3-p392/gems/jquery-rails-3.1.0/vendor/assets/javascripts, /home/valle/.rvm/gems/ruby-1.9.3-p392/gems/coffee-rails-4.0.1/lib/assets/javascripts, /home/valle/.rvm/gems/ruby-1.9.3-p392/bundler/gems/twitter-bootstrap-rails-663760e67b80/app/assets/fonts, /home/valle/.rvm/gems/ruby-1.9.3-p392/bundler/gems/twitter-bootstrap-rails-663760e67b80/app/assets/images, /home/valle/.rvm/gems/ruby-1.9.3-p392/bundler/gems/twitter-bootstrap-rails-663760e67b80/app/assets/javascripts, /home/valle/.rvm/gems/ruby-1.9.3-p392/bundler/gems/twitter-bootstrap-rails-663760e67b80/app/assets/stylesheets, /home/valle/.rvm/gems/ruby-1.9.3-p392/bundler/gems/twitter-bootstrap-rails-663760e67b80/vendor/assets/stylesheets

I thought Sprockets would take all js or css files in all assets folders, precompile, unify and minify them, but now it seems I need to specify the path. How could I solve it? Besides, is it a problem not to have separated javascript and css folders in vendors?

Community
  • 1
  • 1
Marcos Valle
  • 77
  • 2
  • 11

2 Answers2

2

in rails 4 they have removed vendor folder,so,assets will not server from vendor.

in that Rails.application.config.assets.paths not contains vendor,if you want you have to add the path like

in config/application.rb

config.assets.paths << "#{Rails.root}/vendor/assets"
Jenorish
  • 1,694
  • 14
  • 19
  • Thanks for the answer and sorry for the late reply. It seems to work like a charm. Still, vendor folder does exist (at least in rails 4.1.0) and I don't get why it was removed from `Rails.application.config.assets.paths` anyhow. Shouldn't I use `vendor/folders`? What is the correct alternative to use my third-party files then? – Marcos Valle Apr 28 '14 at 02:46
  • Since version 4 vendor and lib directories are not included in the asset pipeline by default.if you want to then you should extend assets path or use `app/assets` folder.if my answer is helpful accept my answer. – Jenorish Apr 28 '14 at 04:44
0

Update application.js file as

//= require jquery
//= require jquery_ujs
//= require twitter/bootstrap
//= require turbolinks
//= require_tree .
//= require otherJsFiles

And in application.css file require other css file as

*= require otherCssFiles

Require each js and css file in application.js and application.css file placed in vendor/assets.

Shamsul Haque
  • 2,441
  • 2
  • 18
  • 20
  • Thanks for the answer. This solutions seems to work, although I did not test it. Requiring each file seems to be very tedious and not much like Rails style. It makes me wonder if Rails assets pipeline does worth it to be used instead of regular calling files directly in my HTML code. Besides, I do not understand why would `vendor/assets` exist as a built in folder. – Marcos Valle Apr 28 '14 at 02:59
  • vendor/assets folder is used to add thirt party css and javascript files. vendor/assets is for assets that are owned by outside entities, such as code for JavaScript plugins and CSS frameworks. It is in rails 3.2 – Shamsul Haque Apr 29 '14 at 06:14