Rails 4 static assets in public/ or app/assets/

守給你的承諾、 提交于 2019-12-02 18:14:23

When you use rake assets:precompile, Rails moves all of the assets from your app/assets folder, to public/assets. This is as a normal browser does not have access to your app directory, but does have access to public.

So, to answer your question, here are my thoughts. If your images are for your sites layout e.g logos or backgrounds, then you should store them in the app/assets/images directory, however, if the images are user generated, such as profile images, then these should be stored directly in something such as public/images. Ideally you would store those in S3 or a CDN, but you're already doing that.

As a bonus, Carrierwave, a Rails image upload gem, uses a public/images type path as the default store for its images, as you can see in their config file:

    # Override the directory where uploaded files will be stored.
    # This is a sensible default for uploaders that are meant to be mounted:
     def store_dir
     "images/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
     end

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!