在Rails应用程序中访问Word文档

I have a number of documents (mainly Word and Excel) that I'd like to make available to users of my Rails app. However, I've never tried something like this before and was wondering what the best way to do this was? Seeing as there will only be a small number of Word documents, and all will be uploaded by me, do I just store them somewhere in my Rails app (i.e. public/docs or similar) or should I set up a separate FTP and link to that? Perhaps there's an even better way of doing this?

#0

I would do as you suggested and put them in public/docs. If you are planning on making an overview/index page for the files and link directly to them it would be easier if they were stored locally instead of a remote FTP server. However, since you are the one who will be uploading and maintaining these files, I think you should go with the option that's easiest for you.

#1

If they're to be publically accessable, you definitely just want to stick them in public somewhere. Write a little helper to generate the URL for you based on however you want to refer to them in your app, for cleanliness (and so if you do change the URL later, for example to bucket your files to keep your directory sizes under control, you don't have to change links all over your app, just in one place.

If, on the other hand, your files are only for logged-in users, you'll need to use something like send_file to do the job, or one of the webserver-specific methods like the X-Sendfile header to check the user is authorised to view the file before sending it back to them.

推荐文章

在Mac OSX上接收电源通知(特别是关机)

在Mac OSX上接收电源通知(特别是关机)

推荐文章

JBoss服务器上特定EJB Jar的日志配置

JBoss服务器上特定EJB Jar的日志配置

推荐文章

如何强制C条件指令缩进?

如何强制C条件指令缩进?

推荐文章

如何检测远程网页是否可用

如何检测远程网页是否可用

推荐文章

FogBugz-使用TortoiseSVN时存储库的url是什么?

FogBugz-使用TortoiseSVN时存储库的url是什么?

推荐文章

在偶数和奇数处添加数字(C#)

在偶数和奇数处添加数字(C#)

推荐文章

如何对任意类型调用GetEnumerator?

如何对任意类型调用GetEnumerator?

推荐文章

如何在WPF ScrollViewer中增加滚动条宽度?

如何在WPF ScrollViewer中增加滚动条宽度?

推荐文章

如何将自定义类保存/序列化到设置文件?

如何将自定义类保存/序列化到设置文件?

推荐文章

TFS-查找连接到任务的所有更改集

TFS-查找连接到任务的所有更改集

推荐文章

从SQL查询创建Breadcrumbs结构

从SQL查询创建Breadcrumbs结构

推荐文章

JDBC瘦Oracle 11g

JDBC瘦Oracle 11g

推荐文章

具有不同输出模型的ASP.NET MVC-Typesafe Html.textbox

具有不同输出模型的ASP.NET MVC-Typesafe Html.textbox

推荐文章

什么是使Linq对象“脏”的最干净的方法?

什么是使Linq对象“脏”的最干净的方法?

推荐文章

如何在文本输入窗体中键入代码?

如何在文本输入窗体中键入代码?

推荐文章

用xml文件配置log4net

用xml文件配置log4net