0

What's considered an "asset" in the Ruby on Rails universe?

Are user generated files, such as images uploaded by the user, considered assets? Where should they be stored in the standard file structure of a Rails project? Should they be kept clear of any asset related directories like:

  • app/assets
  • lib/assets
  • public/assets

Relevant: The Asset Pipeline

2 Answers 2

1

Generally asset is anything that browser loads after it gets the HTML page. Meaning javascript, css and any images. But as you pointed out there are two different image types in a rails project.

1) the images related to your css and layout design, those go under the app/assets/images 2) the images that your users upload, those normally go into the public/system or public/uploads folder depending on what you use to receive the uploads

The lib/assets (or sometimes vendor/assets) is where you supposed to place js/css/images related to your front-end design and provided by third party libs. Say if you want to pull in some css or a js framework, that were you should place it.

And finally public/assets is where rails will compile your layout assets from the app/assets and vendor/assets folders when you run rake assets:precompile task for production.

To have it short, your design stuff goes to app/assets, and the user uploads go into public/system

1
  • Great answer! The way you lay out the difference between an asset that's part of your app and one supplied by the user is something that should be in the Rails docs.
    – franksort
    Feb 10, 2014 at 0:03
0

User-uploaded files are not part of assets, and should definitely be kept clear of asset-related folders. You should put them somewhere in your public directory. I put mine in public/uploads, which is a common convention. And then you should ignore those files in git (or whatever VCS you're using).

Assets are basically: javascript, stylesheets, fonts, and images which are part of the site design itself, not part of the user-uploaded content.

1
  • I hadn't heard of public/uploads as a convention and that helps me out immensely. Thanks!
    – franksort
    Feb 10, 2014 at 0:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.