config/storage.yml
:
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
public: true
config/environments/development.rb
:
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
app/models/user.rb
:
class User < ApplicationRecord
validates :username, presence: true
has_one_attached :avatar
In rails console:
irb> ActiveStorage::Current.host
=> nil
irb> User.find_by_username('david').avatar.url
=> [should generate permanent url]
In rails console:
irb> ActiveStorage::Current.host
=> nil
irb> User.find_by_username('david').avatar.url
URI::InvalidURIError (bad URI(is not URI?): nil)
Rails version:
Rails 6.1.0
Ruby version:
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
There's no documents about setting ActiveStorage::Current.host
before generating public permanent url using the Disk service.