简体   繁体   中英

Ruby on rails files setup

I have some doubts about the folders on which I should put the public files.
We got at the root path a folder called public and some other folders in app (rails 5.0.1 for me), let me show you the ones which sound strange for me:

  • app/assets/ (images | javascripts | stylesheets)
  • app/views/pages

After reading multiple tutorials and existing public projects, I saw that some people put his web template in public ( js, css and images included ).
Yet, in my case, because of I have seen it few times too and found it logic, I have put my template in assets separating my js, sass (in my case) files, and images in the folders already created by the RoR generator.

Additionnal, it seems logic for me to put my files in assets because my main layout gonna take my template files in assets with the framework default API. The following line works for me and gonna load my app/assets/stylesheets/ app.css.scss file

<%= stylesheet_link_tag    'app', media: 'all', 'data-turbolinks-track': 'reload' %>

Hope someone could explain what's the better way, I'm beginner with Rails, thanks.

app/assets/

This is where you put custom assets (images, js/css scripts that you own and custom to your application)

vendor/assets/

This is for third party libraries that you use in your app (carousel js plugin, etc)

.
├── app
│   ├── assets (custom assets specific to your app)  
├── public (static-files like error pages, favicon, etc which does not change much)
├── vendor
│   └── assets (third party libraries that your app uses)

Precompiled Assets

Add all the paths to your assets (images, js/css files) used in your application in assets precomile path in config/initializers/assets.rb (application.css and application.js are included by default)

All the assets when precompiled with

bundle exec rails assets:precompile

This generates public/assets directory with all the assets configured in your precompile path as readily servable static assets which are then served to your application responses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM