rails 4 enabled rails to serve static assets: is it correct? (on heroku)

前端 未结 4 1544
长情又很酷
长情又很酷 2021-02-01 03:15

Environment: heroku

Rails: 4

Ruby: 2

We deployed an app to heroku, and it seemed as though anything in the public folder was not accessible (didn\'t see

相关标签:
4条回答
  • 2021-02-01 04:03

    In previous Rails versions, Heroku injected a plugin that enabled serving of static assets so this issue didn't exist. As this plugin system was removed in Rails 4, they now created a gem which does the same. You enable it in your Gemfile via:

    gem 'rails_12factor', group: :production
    

    See Getting Started with Rails 4.x on Heroku

    You could also of course use a CDN for your assets, but you're not required to.

    For Rails 5+ work on twelve-factor platforms out of the box and the gem is no longer required

    0 讨论(0)
  • 2021-02-01 04:05

    The rails guides are wrong. Try...

    config.assets.serve_static_files = true
    
    0 讨论(0)
  • 2021-02-01 04:09

    This is deprecated in Rails 4.2, and it is now an alias slated to be removed in Rails 5.0

    config.serve_static_assets = true
    

    It should be changed to:

    config.serve_static_files = true
    
    0 讨论(0)
  • 2021-02-01 04:19

    As Dean Winchester mentioned it, it is a good idea to use a CDN for your static assets. In fact when using only Heroku your Rails application would have to be responsible to serve static assets since Heroku Cedar architecture will not do that for you.

    Setting config.serve_static_assets = true is the way to go if you don't want to configure a CDN and use only Heroku.

    0 讨论(0)
提交回复
热议问题