Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveStorage image url isn't correct on localhost #39

Closed
StephenFiser opened this issue Aug 20, 2020 · 7 comments
Closed

ActiveStorage image url isn't correct on localhost #39

StephenFiser opened this issue Aug 20, 2020 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@StephenFiser
Copy link

Image src is prefixed with http://example.org instead of http://localhost:3000.

@julianrubisch julianrubisch added the bug Something isn't working label Aug 31, 2020
@julianrubisch julianrubisch added this to the 0.4.1 milestone Aug 31, 2020
@julianrubisch
Copy link
Contributor

So I dug a bit into this. Surprisingly, even setting everything up in config/initializers/application_controller_renderer.rbdoesn't fix it:

ActiveSupport::Reloader.to_prepare do
  ApplicationController.renderer.defaults.merge!(
    http_host: 'localhost',
    https: false
  )
end
[1] pry(main)> ApplicationController.renderer
=> #<ActionController::Renderer:0x00007fc5a3b907d8
 @controller=ApplicationController,
 @defaults={:http_host=>"localhost", :https=>false, :method=>"get", :script_name=>"", :input=>""},
 @env={"HTTP_HOST"=>"example.org", "HTTPS"=>"off", "REQUEST_METHOD"=>"GET", "SCRIPT_NAME"=>"", "rack.input"=>"", "rack.url_scheme"=>"http"}>

As you can see it's present in @defaults, but not in @env['HTTP_HOST'].

So either I'm not understanding everything correctly (more likely) or this is a Rails bug.

@julianrubisch
Copy link
Contributor

Interestingly, the rails code docs states:

# The template will be rendered in a Rack environment which is accessible through
--
  | # ActionController::Renderer#env. You can set it up in two ways:
  | #
  | # *  by changing renderer defaults, like
  | #
  | #       ApplicationController.renderer.defaults # => hash with default Rack environment
  | #
  | # *  by initializing an instance of renderer by passing it a custom environment.
  | #
  | #       ApplicationController.renderer.new(method: 'post', https: true)
  | #

so this should work?

@StephenFiser
Copy link
Author

Thanks for taking a look into this. Apologies for not getting back to it. Been pretty tied up for the past week.

@julianrubisch
Copy link
Contributor

So, apparently, thanks to @leastbad and @ParamagicDev on the StimulusReflex discord, setting

config.action_controller.default_url_options = {host: "localhost", port: 3000}

should do it. I suspected it had to be some of those config options, just it wasn't clear which default_url_options 😁

Could you try this and confirm? Then I'd update the docs and close the issue...

julianrubisch added a commit that referenced this issue Sep 8, 2020
@julianrubisch
Copy link
Contributor

@StephenFiser could you take a look if #50 looks good to you?

@leastbad
Copy link
Contributor

@StephenFiser
Copy link
Author

@leastbad thanks for sharing! Totally fell off the wagon on this ticket 😬 Been swamped with unrelated items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants