Rails:上传文件或存储网址 [英] Rails: upload a file OR store a url

查看:47
本文介绍了Rails:上传文件或存储网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个表单,允许用户上传文件或输入现有文件的 url.

I'm developing a form where I want to allow users to either upload a file, or enter a url to an existing file.

这个想法是允许用户将各种多媒体"文件附加到条目,其中一些可能是来自他们硬盘驱动器的文件(想想图像、word 文档等),一些可能是 url(youtube 视频、flickr 上的图像)等)

The idea is to allow users to attach various 'multimedia' files to entries, some of which may be files from their hard drives (think images, word documents, etc) and some may be urls (youtube videos, images on flickr, etc)

关于如何实现这一点的任何想法?我目前正在使用carrierwave 来处理文件上传,它似乎运行良好,但我也想存储 url.

Any ideas on how I can accomplish this? I'm currently using carrierwave to handle file uploads, and it seems to work well, but I want to store url's as well.

推荐答案

我可能要做的是在文件上传表单中有一个下拉菜单,以选择文件是来自磁盘还是来自外部 url.

What I will probably do is to have a drop down in the file upload form to select if the file is from the disk or from external url.

默认情况下它会设置为从磁盘",如果他们选择外部网址,你可以使用一些 AJAX 魔法并隐藏文件上传文本框,并有一个文本框来使用外部网址/脚本等.

By default it will set to "from disk", and if they select external url, you could use some AJAX magic and hide the file upload text box and have a text box to use the external url/script etc..

在表格中,可以再保留两列,

in the table, you can keep another two columns,

1 - 外部网址

2 - 文件类别(外部/上传的文件)

2 - file category (external / uploaded file)

通过这种方式,您可以区分文件以及它们如何在视图中显示

by that way you can distinguish the files and how they what to display in the view

HTH

这篇关于Rails:上传文件或存储网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆