Change the ActiveStorage Controller Path

后端 未结 3 847
清歌不尽
清歌不尽 2020-12-17 18:59

Is there a way to customize the attachment urls so instead of

/rails/active_storage/representations/
/rails/active_storage/blobs/

We could

相关标签:
3条回答
  • 2020-12-17 19:29

    Tested the solution by @stwienert. The config.active_storage.routes_prefix option only works for rails 6.0.0alpha and higher branch. The patch is not available for 5.2.2

    I made a fork for 5.2.2 with the patch. https://github.com/StaymanHou/rails/tree/v5.2.2.1

    To use it, simply replace the line gem 'rails', '~> 5.2.2' with gem 'rails', '5.2.2.1', git: 'https://github.com/StaymanHou/rails.git', tag: 'v5.2.2.1'. And run bundle install --force

    coffee-rails gem will be required if you don't have it yet for rails edge install - https://github.com/rails/rails/issues/28965

    0 讨论(0)
  • 2020-12-17 19:38

    Monkey patching is always on your side

    0 讨论(0)
  • 2020-12-17 19:39

    Recently, there was an addition which makes the route prefix configurable: https://github.com/rails/rails/commit/7dd9916c0d5e5d149bdde8cbeec42ca49cf3f6ca

    Just in master branch now, but should be integrated into ~> 5.2.2 have been integrated into Rails 6.0.0 and higher.

    Then, it's just a matter of configuration:

    Rails.application.configure do
      config.active_storage.routes_prefix = '/whereever'
    end
    
    0 讨论(0)
提交回复
热议问题