Catch Ruby errors before your users do. Monitor Ruby production errors in real-time and debug them in minutes, before users notice. Our open source Ruby SDK works with Rails, Sinatra, and more. Use this link and get one month free!

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