When streaming from a worker, path helpers append a domain `https://example.com`
letItCurl opened this issue · 5 comments
here is a video explaining the bug
@letItCurl this happens when you render a view from a background job. In views that are rendered during an HTTP request rails has access to the current request and can infer the host for links and forms from there. But in a background job there's no current request and rails uses a default placeholder host.
You can fix this defining a default host in your application controller.
class ApplicationController < ActionController::Base
def default_url_options
{ host: Rails.application.config.default_host }.compact_blank
end
end
Then set config.default_host
in your environments.
@seanpdoyle not that I'm aware of. This is really a Rails issue, it happens when rendering from a background job, even without any Turbo involved. There's an issue open to make this configuration simpler and more explicit.
@afcapel thank you so much for the help!
@seanpdoyle thank you also for checking this out, I was about to ask for the doc hahah!
``Hi for all.
@letItCurl this happens when you render a view from a background job. In views that are rendered during an HTTP request rails has access to the current request and can infer the host for links and forms from there. But in a background job there's no current request and rails uses a default placeholder host.
You can fix this defining a default host in your application controller.
class ApplicationController < ActionController::Base def default_url_options { host: Rails.application.config.default_host }.compact_blank end endThen set
config.default_host
in your environments.
@afcapel this not work to me.
i'm still received a url broken.
received: http://localhost/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MTYsInB1ciI6ImJsb2JfaWQifX0=--9c8a7496ec8b4bc9d2451f1a55d2d7e4d048b1d1/https___dev-to-uploads.s3.amazonaws.com_i_zpek00ubevoxvn458b01.avif?locale=pt-BR
expected: http://localhost:3000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsiZGF0YSI6MTYsInB1ciI6ImJsb2JfaWQifX0=--9c8a7496ec8b4bc9d2451f1a55d2d7e4d048b1d1/https___dev-to-uploads.s3.amazonaws.com_i_zpek00ubevoxvn458b01.avif?locale=pt-BR
My files
application_controller
def default_url_options
{ locale: I18n.locale, host: Rails.application.config.default_host }.compact_blank
end
development.rb
require "active_support/core_ext/integer/time"
Rails.application.configure do
config.default_host = "localhost"
end
my post
model:
after_create_commit do
broadcast_prepend_to "posts", partial: 'posts/post', locals: { post: self }
end
after_update_commit do
broadcast_replace_to "posts", target: "post_#{id}", partial: 'posts/post', locals: { post: self }
end
after_destroy do
broadcast_remove_to "posts", target: "post_#{id}"
end