RubyFlow The Ruby and Rails community linklog

Ruby on Rails Active Storage how to change host for url_for

By default ActiveStorage url points to http://example.com:

# irb
a = Account.last
app.url_for(a.avatar)
# => "http://www.example.com/rails/active_storage/blobs/xxxxxxxxxx/dog.jpg" 

in order to change the host you need to set:

# config/enviroments/development.rb
Rails.application.routes.default_url_options[:host] = 'localhost:3000'

#irb
app.url_for(a.avatar)
# => "http://localhost:3000/rails/active_storage/blobs/xxxxxxxxxx/dog.jpg"

more info at: Ruby on Rails Active Storage how to change host for url_for

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in