更改ActiveStorage控制器路径
有没有办法自定义附件url而不是
/rails/active_storage/representations/ /rails/active_storage/blobs/
我们可以这样:
/custom_path/representations/ /custom_path/blobs/
最近,有一个添加使路由前缀可配置: https : //github.com/rails/rails/commit/7dd9916c0d5e5d149bdde8cbeec42ca49cf3f6ca
现在只在master分支中,但应该集成到〜> 5.2.2及更高版本。
然后,这只是配置问题:
Rails.application.configure do config.active_storage.routes_prefix = '/whereever' end
猴子补丁总是在你身边😉。
只是为了对下一个补丁感兴趣,我可以更改ActiveStorage Controller路径:
module MapperMonkeypatch def map_match(paths, options) paths.collect! do |path| path.is_a?(String) ? path.sub('/rails/active_storage/', '/custom_path/') : path end super end end ActionDispatch::Routing::Mapper.prepend(MapperMonkeypatch)
一切似乎都有效🙂。