-
-
Save juggy/768696 to your computer and use it in GitHub Desktop.
ActionController::Base.asset_host = Proc.new { |source, request| | |
if request.env["REQUEST_PATH"].include? ".pdf" | |
"file://#{Rails.root.join('public')}" | |
else | |
"#{request.protocol}#{request.host_with_port}" | |
end | |
} |
@timurvafin not sure. I believe root_url is for relative paths. If my html or css is requiring a file at full url (http://domain.com/file) then it won't work.
@juggy, think solution with asset_host will not work either b/c it's used only by assets helpers which generate only paths (without proto & domain)
Think again. Asset hosts are there in production to roll out things like cloudfront and multiple assets servers. It can be used to avoid pipelining of assets in the rowser also (using asset1, asset2 hosts for example) . This particular gist is used in production for 2 of our apps for more than a year without any glitches.
Thank you for the gist!
Here is correct version with slash at the end for root_url option. Works for me too on heroku.
PDFKit.configure do |config|
config.root_url = "file://#{Rails.root.join('public')}/"
end
If you use the OP's method:
consider using this instead
if request.path.include? ".pdf"
You can use root_url option with the same effect