What is the best way to organize assets in a rails application

As I continue to progress through my application, my stylesheet quickly outgrows. I've read the Asset Pipeline Rail Guide and browsed the internet for a reputable source and I am still unable to lose track of the rails to keep things in order.

Before I try to develop the system myself, I was hoping to get some suggestions from you.

Is there a known "best practice" when it comes to organizing assets? If not, what worked for you?

At the moment, my setup is this:

app/assets/stylesheets >

      

application.css, application-RESPONSIVE.css

any code specific to body, containers, nav, footer

controller.scss, controller-RESPONSIVE

* any code specific to this controller

lib/assets/stylesheets >

      

reset.css

in application.css i am using

*= require reset
*= require_tree .
*= require_self

      

To get all the styles, but , I also wondered, is it better to set it in front of the tree as a means of overriding the main styles if needed?

+3


source to share


1 answer


Is there a known "best practice" when it comes to organizing assets?

Asset organization:

In Rails, pipeline assets can be placed inside an application in one of three locations: application / assets, lib / assets, or provider / assets.

1) App / Assets are for assets owned by the app, such as custom images, JavaScript files or stylesheets.

2) lib / assets are for your own libraries' code, which is really inappropriate for application scope or those libraries that are used for different applications.

3) vendor / assets are for assets owned by external organizations like code for JavaScript plugins and CSS frameworks.

Is it better to put yourself in front of the tree as a means of overriding the base styles if needed?

application.css is what is called the manifest file. Now it won't make much difference when switching with the tree, but it will change its position in the boot sequence. Consider this ...



Once you put your assets in their logical locations, you can use manifest files to tell Rails (via the Sprockets gem) how to combine them to create separate files. These manifest files contain directives - instructions that tell Sprockets what files are required to generate a single CSS or JavaScript file.

Additional Information:

Another thing that Rails does is generate stylesheets for you when you run a command rails generate

in the terminal. When you create a new controller, you will see the stylesheet with the controller name in your assets. It will look like app / assets / stylesheets / newcontroller.css.scss

Besides what steve klein said.

Hope this helps you.

UPDATE:

I tried looking for examples on github, but all the apps I found were too simple and havent shown any advanced organization for a lot of files.

I recommend you check out the open source site . I looked at some of the projects out there and they seem complex enough to keep you interested enough. In particular, see the discourse appendix . Discourse was co-founded by Jeff Atwood, co-founder of Stack Overflow. This, I suppose, speaks for itself;)

+3


source







All Articles