Is there a way to configure attachment urls so that instead
/rails/active_storage/representations/ /rails/active_storage/blobs/
We could have something like this:
/custom_path/representations/ /custom_path/blobs/
Recently, an addition has appeared that allows you to configure the route prefix: https://github.com/rails/rails/commit/7dd9916c0d5e5d149bdde8cbeec42ca49cf3f6ca
Just in the main branch now, but should be integrated in ~> 5.2.2 and higher.
Then this is just a configuration issue:
Rails.application.configure do config.active_storage.routes_prefix = '/whereever' end
Sorry, I'm afraid Active Storage does not support this.
, , Active Storage , , . , Active Storage URL-, ActiveStorage::Service::DiskService#url ActiveStorage::Service::DiskService#url_for_direct_upload. ( , , .) , .
ActiveStorage::Service::DiskService#url
ActiveStorage::Service::DiskService#url_for_direct_upload
😉.
, ActiveStorage:
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)
, , 🙂.
Tested @stwienert solution. The option config.active_storage.routes_prefixworks only for rails 6.0.0alpha and higher. Patch not available for 5.2.2
config.active_storage.routes_prefix
I made a plug for 5.2.2 with a patch. https://github.com/StaymanHou/rails/tree/v5.2.2.1
To use it, simply replace the string 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 runbundle install --force
gem 'rails', '~> 5.2.2'
gem 'rails', '5.2.2.1', git: 'https://github.com/StaymanHou/rails.git', tag: 'v5.2.2.1'
bundle install --force
coffee-railsa gem will be needed if you do not already have one to install the edge rails - https://github.com/rails/rails/issues/28965
coffee-rails
Source: https://habr.com/ru/post/1695161/More articles:How does packaging work when sorting? - c #Structure of a synchronous application in Node.js and MongoDb - synchronizationExpandableListView - border around a parent and its children - androidEffectively determine if part of a string is included in the / dict list keys? - pythonPython: analyze list comprehension with - performanceGit checkout -p Regular Expression Search HEAD - gitJava 8: Despite the fact that you avoid the work of the terminal, see "The thread has already been operated or is closed" - java-8Use java argument parameter in IntelliJ - javaPrint var inside a string - javascriptGet the waterfall category names - vbaAll Articles