在Ruby/rails中打开回形针附加的Word文档

问题描述:

我有一个使用回形针的带有文件附件的Rails应用程序.图像和pdf可以正常工作,因为如果我单击链接的附件,则会打开图像或pdf.如果单击鼠标右键,则可以另存为.

I have a rails app with file attachments using paperclip. Images and pdfs work fine in that if I click on the linked attachment, the image or pdf opens. If I right click, I can do a save-as.

但是,对于Office文件(如word.docx),我只能下载该文件.如果我去做Dos并输入文件名,它将以MS word形式打开.因此,我认为我应该能够使用系统或系统调用,只需将回形针的附件名称(即attach.image.url)传递给dos,文件便会打开.我想我想要的命令应该是

However, with Office files such as word.docx, I can only download the file. If I go do Dos and type the filename, it will open in MS word. Therefore, I think that I should be able to use the system or system call and just pass the attachment name from paperclip (ie attachment.image.url) to dos and the file should open. I think the command I want would be something like

system(attachment.image.url)

我不知道如何编写语句来做到这一点.

I can't figure out how to write the statement to do that.

您的浏览器不会(也不应该)允许您执行浏览器本身之外的任何操作,这意味着无需某些外部应用程序即可调用Rails客户端计算机上的应用程序,则必须先下载Word文档,然后才能打开它.

Your browser will not (and should not) allow you to execute anything outside of the browser itself, this means that without some external app making the call to your Rails app from the clients machine, you will not be able to open the Word doc without downloading it.

您可以在浏览器中打开图像和PDF,因为该浏览器支持它们,但是大多数浏览器不会打开Word文档.

You are able to open the images and PDFs in the browser because the browser supports them, but most browsers won't open Word docs.

您既可以让用户下载文件,也可以使用第三方查看器来打开浏览器内部的doc一词.

You can either have the user download the file, or maybe use a third party viewer that you can open the word doc with inside the browser.