I send a pdf to the user using this line in my controller:
format.pdf { render :file => pdf_file_path }
This has been working fine. But, on one specific file (meaning specific
file
content) I get this error, which makes it look like Ruby via Rails is
trying
to interpret the content of the file as code. Because other files are
downloading fine, and from the error message I conclude that Ruby is in
fact
trying to interpret the file content:
So the million dollar question is what could make Rails decide to
interpret
the content of a file which we are asking for it to pass down to the
user?
And better yet, is there a way I can tell Rails “hey, this is a file,
lay
off”?
So the million dollar question is what could make Rails decide to interpret
the content of a file which we are asking for it to pass down to the user?
And better yet, is there a way I can tell Rails “hey, this is a file, lay
off”?
If you actually just want to send a file, use send_file. render :file
means 'here is a template, please execute it".
On Fri, Dec 10, 2010 at 6:29 AM, Frederick C. < [email protected]> wrote:
content) I get this error, which makes it look like Ruby via Rails is
/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid
The actual error is longer but you get the point. There is no line 736 in
É ¿£˚í¬É&F« òzÍÅz5µ¨qÔ:/ÌRwQ¿‡”‡ñ∫ ¨a¨ÍÎ∂!NáatÃÃpí\ÏP´Ô/vò⁄ôπÿhÍóìH4
off"?
If you actually just want to send a file, use send_file. render :file
means 'here is a template, please execute it".
Thanks, right on. One question though: if I call “render :text = >
response”
does this also get interpreted? If I am returning xml (which has an
embeded
pdf doc), am I better of using send_data or render :text?
On Fri, Dec 10, 2010 at 9:19 AM, Frederick C. < [email protected]> wrote:
render :text will just dump what you pass straight into the response
( it’s what send_data uses internally).
send_data is mostly a convenience that sets headers like Content-
disposition for you. If you have an actual file then send_file can be
more efficient if you use the x-send-file or stream options since
those don’t entail loading the whole file into your rails process.
Thanks, right on. One question though: if I call “render :text = > response”
does this also get interpreted? If I am returning xml (which has an embeded
pdf doc), am I better of using send_data or render :text?
render :text will just dump what you pass straight into the response
( it’s what send_data uses internally).
send_data is mostly a convenience that sets headers like Content-
disposition for you. If you have an actual file then send_file can be
more efficient if you use the x-send-file or stream options since
those don’t entail loading the whole file into your rails process.
Fred
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.