简体   繁体   English

在Rails 4中上传多文件

[英]Multi file uploads in rails 4

I'm having a few problems with multi file uploads in rails 4, I've got it working using carrierwave and polymorphic associations but its creating a file filed for every image in the view. 我在Rails 4中上传多个文件时遇到了一些问题,我已经使用载波和多态关联使它工作了,但是它为视图中的每个图像创建了一个文件。 This makes sense as its creating fields for the associated model. 这是有意义的,因为它为关联模型创建了字段。

If there is a better or more standard way of doing this in rails 4 I'd be grateful for your advise. 如果在rails 4中有更好或更标准的方法,我将不胜感激。

Here is a gist to what I'm doing: https://gist.github.com/lperry65/5805b5f41495f8a820b7 这是我正在做的要点: https : //gist.github.com/lperry65/5805b5f41495f8a820b7

Screen Shot http://cl.ly/image/3y3w203z3G1f 屏幕截图http://cl.ly/image/3y3w203z3G1f

There seems to be lots of ways to accomplish this, but most of the info I found while googling is for rails 3. It's my intention to use UploadiFive for the front end once I iron out the wrinkles. 似乎有很多方法可以实现,但是我在谷歌搜索时发现的大多数信息都是关于rails 3的。一旦消除皱纹,我打算在前端使用UploadiFive。

http://www.uploadify.com/download/download-uploadifive-standard/ http://www.uploadify.com/download/download-uploadifive-standard/

Changing <%= f.fields_for :images do |i| 更改<%= f.fields_for:images | i | %> to <%= f.fields_for :images[0] do |i| %>到<%= f.fields_for:images [0]做| i | %> stopped the file input from being duplicated for every image. %>停止为每个图像复制文件输入。 I can't say I'm happy with it but it works for now. 我不能说我对此感到满意,但它现在可以使用。

I'll update the gist to reflect any other changes, it's all working now so I'll leave it until I find a better solution. 我将更新要点以反映其他任何更改,所有这些现在都在工作,所以我将其保留,直到找到更好的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM