How to organize css and js?

3

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

app / assets / javascripts:   Home   admin Home   template Home   admin.js // make the admin dir call, it works normally Home   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:   Home   admin Home   template Home   admin.css // make the admin dir call, it works normally Home   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 layout application.html.haml I reference the application.css and application.js. My question is if this organization is correct because it was reading in the guide and I see that it has the public folder and vendor for css and js but I do not know when to use it.

    
asked by anonymous 23.02.2015 / 02:55

2 answers

1

Previously rails put images, css and javascript in public really, but it is currently advised to use the assets folder for these files:

  

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

Documentation

The organization within the assets folder can be as follows (as described in the documentation sent in 2.2 Asset Organization)

app / assets for the assets of the application itself.

lib / assets for your own libraries, and that do not fit the scope of the application or shared libraries with another application

vendor / assets is for assets belonging to external entities, such as javascript plugins and css frameworks. codes that reference other files here need to be tailored to use helpers as asset_path.

In other words, the assets placed in public still work and are served as static files depending on your settings. Files in assets 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 not directly served directly   production.

    
23.02.2015 / 18:25
0

I do not know if this will answer your question, but it will serve as a suggestion.

Currently I use Grunt Js ( link ) to: Minify (css, javascript); concatenate several files in only one; "compile jquery code".

It has several plugins ( link ), which give you the ability to create various forms of automation.

It works on the basis of NodeJs ( link ).

A step by step in Portuguese, link , which teaches you where to start and gives some plugin tips and configuration.

    
23.02.2015 / 13:35