Open a paperclip attached word doc in Ruby/rails

人走茶凉 提交于 2019-12-13 08:57:50

问题


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.

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.


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/33308929/open-a-paperclip-attached-word-doc-in-ruby-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!