Rails gem Dragonfly default storage path changing

547 Views Asked by At

Dragonfly saves files under the (environment) directory, like:

public/system/dragonfly/development/

or

public/system/dragonfly/production/

is it possible to make the common directory and save all under (dragonfly) for production and development both?

public/system/dragonfly/
1

There are 1 best solutions below

0
Neon_10 On BEST ANSWER

I hope this will help those who has such question:

You should correct the line with root_path in the initializer file config/intializers/dragonfly.rb

root_path: Rails.root.join('public/system/dragonfly', Rails.env)

and remove Rails.env for the path had no veriables.

#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