Rails gem Dragonfly 默认存储路径更改

Rails gem Dragonfly default storage path changing

Dragonfly 将文件保存在(environment) 目录下,如:

public/system/dragonfly/development/

public/system/dragonfly/production/

可不可以制作一个common目录,全部保存在(dragonfly)下,用于生产和开发?

public/system/dragonfly/

希望对有这样疑问的人有所帮助:

您应该更正初始化文件 config/intializers/dragonfly.rb

中带有 root_path 的行
root_path: Rails.root.join('public/system/dragonfly', Rails.env)

并删除 Rails.env 因为路径没有变量。

#config/intializers/dragonfly.rb

require 'dragonfly'

# Configure
Dragonfly.app.configure do
  plugin :imagemagick

  secret "e83b8affbf1c807c7788c07d27e70e79fb0459f8e2c4375b59e60a3da11631e5"

  url_format "/media/:job/:name"

  datastore :file,
    root_path: Rails.root.join('public/system/dragonfly', Rails.env),
    server_root: Rails.root.join('public')
end

# Logger
Dragonfly.logger = Rails.logger

# Mount as middleware
Rails.application.middleware.use Dragonfly::Middleware

# Add model functionality
if defined?(ActiveRecord::Base)
  ActiveRecord::Base.extend Dragonfly::Model
  ActiveRecord::Base.extend Dragonfly::Model::Validations
end