Skip to content

Commit f297e76

Browse files
committed
Tweak image storage settings to support pdf previews in dev, prod, staging (will prob need to install some libraries on DO)
1 parent 3f93667 commit f297e76

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

config/environments/development.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,20 @@
2929
config.cache_store = :memory_store
3030

3131
# Store uploaded files on the local file system (see config/storage.yml for options).
32+
# Active Storage
3233
config.active_storage.service = :local
33-
Rails.application.routes.default_url_options[:host] ||= "http://localhost:3000"
34+
35+
# URL helpers, *_url helpers, mailers
36+
Rails.application.routes.default_url_options[:host] ||= "localhost:3000"
37+
38+
# blob.url, disk service
39+
config.after_initialize do
40+
ActiveStorage::Current.url_options = {
41+
protocol: "http",
42+
host: "localhost",
43+
port: 3000
44+
}
45+
end
3446

3547
# Don't care if the mailer can't send.
3648
config.action_mailer.raise_delivery_errors = false

config/environments/production.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@
4949
# Store uploaded files on the digitalocean (see config/storage.yml for options).
5050
config.active_storage.service = :digitalocean
5151

52-
Rails.application.routes.default_url_options[:host] = ENV.fetch("APP_HOST", "localhost")
52+
app_host = ENV.fetch("APP_HOST", "localhost")
53+
54+
Rails.application.routes.default_url_options[:host] = app_host
55+
56+
config.after_initialize do
57+
ActiveStorage::Current.url_options = {
58+
protocol: Rails.env.production? ? "https" : "http",
59+
host: app_host
60+
}
61+
end
5362

5463
# Assume all access to the app is happening through a SSL-terminating reverse proxy.
5564
config.assume_ssl = true

config/environments/staging.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22

33
# Override production settings here
44
Rails.application.configure do
5+
# Attachment handling
6+
config.active_storage.service = :digitalocean
7+
app_host = ENV.fetch("APP_HOST", "localhost")
8+
Rails.application.routes.default_url_options[:host] = app_host
9+
config.after_initialize do
10+
ActiveStorage::Current.url_options = {
11+
protocol: Rails.env.development? ? "http" : "https",
12+
host: app_host
13+
}
14+
end
515
end

0 commit comments

Comments
 (0)