in my rails app, I need to pass back a image.
I have a 1x1.gif tracking pixel in my route as follows:
match \"/_ctrack.gif\" => \"email_tracking_
Is there a reason that you cannot save the file to public/_ctrack.gif
, remove the route, and let the underlying web server serve the image?
If you need to process the image from disk, just use open on the local filename:
send_data open("#{Rails.root}/path/to/file.gif", "rb") { |f| f.read } .......
The rb
sets the file to open
and binary
modes.
Wouldn't be better to use send_file instead?
send_file Rails.root.join("public", "file.gif"), type: "image/gif", disposition: "inline"