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”?
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:
exception.message: \"compile error\\n\\\n
/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char
`\\\\225' in expression\\n\\\n
/media/lqidatastore/production/temp/297_standard_view.pdf:736: Invalid char
`\\\\263' in expression\\n\\\n
Are you sure it is a rails error? Does it have a conventional ruby
stack trace dump? If so can you post it? What do you see in the
rails log?
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"?
If you actually just want to send a file, use send_file. render :file
means 'here is a template, please execute it".
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".
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 6:29 AM, Frederick Cheung <
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.