11

有没有办法自定义附件网址而不是

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

我们可以有这样的东西:

/custom_path/representations/
/custom_path/blobs/
4

3 回答 3

9

最近,有一个添加使路由前缀可配置:https ://github.com/rails/rails/commit/7dd9916c0d5e5d149bdde8cbeec42ca49cf3f6ca

现在就在 master 分支中,但应该集成到~> 5.2.2已经集成到Rails 6.0.0和更高版本中。

然后,这只是一个配置问题:

Rails.application.configure do
  config.active_storage.routes_prefix = '/whereever'
end
于 2018-09-17T12:37:29.293 回答
5

猴子补丁总是在你身边。

只是为了对下一个补丁感兴趣,我可以更改 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)

一切似乎都有效。

于 2018-07-12T09:44:15.273 回答
0

通过@stwienert 测试了解决方案。该config.active_storage.routes_prefix选项仅适用于 rails 6.0.0alpha 和更高版本的分支。该补丁不适用于 5.2.2

我用补丁为 5.2.2 做了一个分叉。https://github.com/StaymanHou/rails/tree/v5.2.2.1

要使用它,只需将该行替换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-rails如果您还没有安装 rails edge 需要 gem - https://github.com/rails/rails/issues/28965

于 2018-12-11T04:54:30.790 回答