Search code examples
ruby-on-railsrails-activestorage

Get Full URL for ActiveStorage image


The following will return a URL that will work, but is there a better method that doesn't require the concatenation of strings? I do not want to expose the service_url since that URL expires.

 root_url + url_for(object.image.variant(resize: '140x140')) 

Ultimately, I would like to do something like this

object.image.variant(resize: '140x140').absolute_url

Solution

  • I'm not sure if this is the recommended way, but you can use the polymorphic_url helper:

    polymorphic_url object.image.variant(resize: '140x140')