We've moved discussions to Discord

Issue with Hotwire stream and avatar_url_for

Carl Brand •
Hey, I've started playing with Hotwire and noticed an issue when I stream comments using turbo the helper avatar_url_for the image url is set to "example.org" 

Once the page is refreshed it returns to "localhost:5000

I've only seen this mentioned once that says to set 
config.action_controller.default_url_options

It fixes the issue but just wondering if its the correct way? Does this mean it would also need to be set for production etc.
Chris Oliver •
Background jobs don't have a request to determine the host and port from. Thats why you have to set the action controller default url options.

I believe we have to comment it out by default because we don't know if you're using localhost or lvh.me or something else unfortunately.
Porter Bayne •
What about in a Helper?  I'm adjusting `avatar_url_for` to return a default image if no avatar exists and when it comes via Hotwire broadcast, the image_url won't resolve.
Tabish Iqbal •
You can try <%= image_tag url_for... %>. see if that helps.
Porter Bayne •
Thanks!  What I got working was

1) config.action_controller.default_url_options = {host: "myapp.local", port: "3000"} got the user's avatar working
2) image_path "default_image" in the helper for the default image 

This works for me in all cases, even over Hotwire broadcast from the model.
Notifications
You’re not receiving notifications from this thread.