ruby-on-rails – How to organize css and js?


I purchased a free template and I'm applying it to my blog's main page. I created an admin for this blog and I have a question if my organization of assets is correct. Here is the structure:

admin.js // make the call from the admin dir, it works normally

And the call inside application.js looks like this:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require template/js/jquery.poptrox.min.js
//= require template/js/skel.min.js
//= require template/js/init.js

admin.css //call the admin dir, it works normally

And the call inside application.css looks like this:

*= require template/css/skel.css
*= require template/css/style.css
*= require template/css/style-xlarge.css
*= require_self

and in the application.html.haml layout I make the reference of application.css and application.js. My question is if this organization is correct because I was reading in the guide and I see that it has the public and vendor folder for css and js but I don't know when to use it.


Rails used to put images, css and javascript in public really, but nowadays it is advised to use the assets folder for these files:

In previous versions of Rails, all assets are located in subdirectories of public such as images, javascripts and stylesheets.


The organization within the assets folder can look like this (as described in the documentation sent in 2.2 Asset Organization)

app/assets for the app's own assets.

lib/assets to their own libraries, and which do not fall within the scope of the application or libraries shared with another application

vendor/assets is for assets owned by external entities such as javascript plugins and css frameworks. code that references other files here needs to be adapted to use helpers like asset_path.

That is to say assets placed in public still work and are served as static files depending on your settings. Asset files are automatically served, after being precompiled, in public/assets when in production.

In production, Rails precompiles these files to public/assets by default. The precompiled copies are then served as static assets by the web server. The files in app/assets are never served directly in production.

Scroll to Top