Rails:将多个文件作为嵌套模型上传

发布于 2024-10-09 21:00:34 字数 350 浏览 2 评论 0原文

我正在开发一个项目,需要上传多个不同类型的文件。

我想将文件作为嵌套模型存储在数据库中(我不确定这是否也是最好的主意)。可以称为文档。

我有以下问题。

  1. 我是否必须使用插件/gem,我没有找到它的任何简单实现。

  2. 如果是,最好的 gem/插件是什么?据我所知,回形针不支持存储在数据库中,但 Attachment_fu 支持。

  3. 是否可以使用 jQuery 来实现而不刷新页面?

我还想处理一些有关文件大小和类型的错误。

问候, Hardik

PS:我使用的是rails 2.3.5

I am working on a project where it is needed to upload multiple files of different type.

I want to store the files in the database (I am not sure if this is the best idea also) as a nested model. May be called document.

I have following questions.

  1. Do I have to use a plugin / gem, I didn't find any simple implementation of it.

  2. If yes, what would be the best gem / plugin for that ? As far as I could fine out paperclip doesn't support storing in the database but attachment_fu does.

  3. Is it possible to do it with jQuery without refreshing the page ?

I would also like to handle some errors regarding filesize and types.

regards,
Hardik

PS: I am using rails 2.3.5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

内心旳酸楚 2024-10-16 21:00:34

首先,永远永远不要在数据库中存储文件!

如果将文件保存在数据库中,则必须查询它并遍历整个 Rails 堆栈才能获取文件。正如您可以想象的那样:这很慢。网络服务器在传送文件和静态内容方面要快得多,因为它们是为此而构建的。如果您的网站变得更大,最好将静态内容放在其他地方,例如 Amazon S3 或其他资产托管。如果您的文件不在数据库中,它们是独立的并且易于移动(image_tag 助手是您最好的朋友)。

  1. 当然,您不必必须使用插件/gem。您始终可以自己实现所有内容,但这当然是一个坏主意,因为其他人已经发明了这个轮子,这为您节省了大量时间。

  2. 回形针仍然是我的选择,非常好,并且在我看来比attachment_fu更容易处理。它还具有您请求的验证。

  3. 当然,有http://www.uploadify.com/ 例如,允许多个文件上传以及您可以想象的东西:)

问候,

Alex

first of all, never ever store files in the database!

If you save files in the database, you have to query it and go through the whole rails stack just to get the file. As you can imagine: this is slow. A webserver is much faster in delivering files and static content, because they are build to do so. If your site becomes bigger, it would be a good idea to put your static content somewhere else, like Amazon S3 or other asset hosts. If your files aren't in the database, they are independent and easily to move (the image_tag helper is then your best friend).

  1. Of course you don't have to use a plugin/gem. You can always implement everything on your own, but that's of course a bad idea, because others have invented this wheel already which saves you a lot of time.

  2. paperclip is still my choice, quite nice and in my opinion easier to handle than attachment_fu. It also has your requested validations.

  3. Sure, there is http://www.uploadify.com/ for example, allows multiple file uploads and the things you can imagine :)

Regards,

Alex

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文