You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Grover in a docker context where a container is running rails (called web) and another container is running chrome (called pdf)
When I render an image, for example, which brings my asset_host value in the asset path: <img src="http://localhost:3000/assets/insert-your-logo-e3833ddb.png" />
To workaround it, I replace http://localhost:3000 with a host containerized name, in this case, http://web:3000
Is it good to consider replacing the absolute host by configuration?
I created a method (inside ApplicationController) to reuse in controllers which render pdf files:
defrender_to_pdf(options)filename=options.delete(:filename)html=render_to_string(**options)html=html.gsub("http://localhost:3000","http://web:3000")# <-- POINT WHERE DO THE REPLACEputs"html: #{html}"send_dataGrover.new(html).to_pdf,filename: filename,type: "application/pdf",disposition: "inline"end
Thanks!
The text was updated successfully, but these errors were encountered:
rafaeldev
changed the title
Change host name
Option to change absolute path (perhaps, only in container context)
Feb 12, 2025
You could potentially set this via the asset host config
config.asset_host = 'http://web:3000'
So long as your docker host can also resolve web appropriately
Although doing what you're doing doesn't seem overly harmful.. assuming you control the content being rendered. You could potentially make the search a little more explicit to minimise any accidental find/replaces. ie something like (not tested):
The change on config.asset_host changes the browser load asset behavior. I'm satisfied with the "workaround" but could it stay as a lib config behavior? Does it make sense?
I don't know if my scenario is common, otherwise, we can close this issue.
Hi everyone!
I'm using Grover in a docker context where a container is running rails (called web) and another container is running chrome (called pdf)
When I render an image, for example, which brings my
asset_host
value in the asset path:<img src="http://localhost:3000/assets/insert-your-logo-e3833ddb.png" />
To workaround it, I replace
http://localhost:3000
with a host containerized name, in this case,http://web:3000
Is it good to consider replacing the absolute host by configuration?
Below, the main points of by code:
docker-compose.yml
initializers/grover.rb
I created a method (inside
ApplicationController
) to reuse in controllers which render pdf files:Thanks!
The text was updated successfully, but these errors were encountered: