Like most Ruby developers you have to set a
default_url_options
on a Ruby on Rails project.
Depending on the use case you have to set several of them with different values.
The name of the method default_url_options
is the same, but it is used in
different contexts
(controller,
mail, or file
storage, it may be
confusing and can even have side effects for your project you have to figure out
yourself. Depending on the value you set, they may be reused in other contexts
like
ActiveStorage,
ActionMailer, and
third-party gems like devise. I couldn’t
find any official documentation for the most common cases (web, mail, file
storage, test), I’ve written one.
Using ActiveStorage with external services like AWS S3 for saving and surfing
attachments like images is great. The setup is well explained in Active Storage
Overview in Ruby
on Rails Guides.
But if you start using it, you will maybe encounter some problems, which are not
that easy to find or debug, as they mostly appear in production. One of the
problems we encountered was a Mixed
content
related to ActiveStorage. This was not a big problem at first, as you get only a
warning in a browser with default configuration. But after we added an iOS App,
which was using
WkWebViews, some
random redirects to AWS S3 images stopped working. We couldn’t even see
connections for these images to ActiveStorage endpoint of our Ruby on
Rails Application in logs, which made it harder to
debug.