StatusCode: Our Weekly Programming Newsletter. You're not just a Rubyist, you're a software developer, right? :-) Check out StatusCode Weekly, our language and architecture agnostic newsletter that covers the biggest news across the entire software development world.

RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!

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