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

Question:

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:

app/assets/javascripts:
admin
template
admin.js // make the call from the admin dir, it works normally
application.js

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

app/assets/stylesheets:
admin
template
admin.css //call the admin dir, it works normally
application.css

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.

Answer:

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.

Documentation

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
AllEscort