Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 521
John Pollard Avatar asked Jan 02 '23 15:01

John Pollard


1 Answers

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')
like image 72
Tom Rossi Avatar answered Jan 05 '23 14:01

Tom Rossi