将Rails与Paperclip和SWFUpload一起使用 [英] Using Rails with Paperclip and SWFUpload

查看:163
本文介绍了将Rails与Paperclip和SWFUpload一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用用户模型进行了基本的Rails应用测试,该模型具有使用回形针处理的光场.我创建了能够创建/编辑用户的视图,并且照片上传效果很好.

I have a basic rails application test with a user model that has a photo field handled with paperclip. I created the views to be able to create/edit an user and the photo uploading is working nicely.

<h1>Editing user</h1>

<% form_for :user, @user, :url => user_path(@user), :html => { :method => "put", :multipart => true } do |f| %>
  <%= f.error_messages %>

  <p>
    <%= f.label :first_name %><br />
    <%= f.text_field :first_name %>
  </p>
  <p>
    <%= f.label :last_name %><br />
    <%= f.text_field :last_name %>
  </p>
  <p>
    <%= f.label :file %><br />
    <%= f.file_field :file %>
  </p>

  <p>
    <%= f.label :photo %><br />
    <%= f.file_field :photo %>
  <p>
    <%= f.submit 'Update' %>
  </p>

<% end %>

<%= link_to 'Show', @user %> |
<%= link_to 'Back', users_path %>

然后,我想将SWFUpload集成到我的应用程序中.我尝试遵循此教程并运行测试项目,但没有成功:浏览按钮没有成功打开文件对话框,并引发与selectFiles()方法有关的错误#2176.

Then, I wanted to integrate SWFUpload in my application. I tried to follow this tutorial and run the test project without any success: the browse button doesn't open a file dialog and an error #2176 is threw which is about the selectFiles() method.

首先,问题出在Flash v.10上,该版本与该项目随附的旧版本的SWFUpload(2.1.0)不兼容:现已弃用selectFiles().因此,我尝试升级到SWFUpload 2.2.0版,该版本现在使用button_placeholder_id设置,但是我无法获得任何示例.

First, the problem is about Flash v.10 that isn't compatible with the old version of SWFUpload (2.1.0) included with the project : selectFiles() is now deprecated. So I tried to upgrade to SWFUpload v. 2.2.0 which now use a button_placeholder_id setting but I can't get any example to work.

因此,我对如何使用SWFUpload初始化以及如何在表单中使用它感到迷lost,因此我可以上载和保存照片.有帮助吗?

So i'm a bit lost about how to use SWFUpload initialization and about and to use it in my form so I can upload and save a photo. Any helps?

推荐答案

要将照片文件字段ID传递给SWFUpload,您的字段ID将为user_photo(来自< input type ='file'id =' user_photo'.../>),因此使用

For passing the photo file field id to SWFUpload, the id of your field is going to be user_photo (from <input type='file' id='user_photo'.../>), so initialize swfupload with

var swfupload = new SWFUpload({button_placeholder_id:'user_photo' ... });

它将用swf上传器替换文件字段.

which will replace the file field with a swf uploader.

请记住,默认情况下,文件将作为"Filedata"参数上传.从技术上讲,您可以将其更改为'user [photo]',但显然在Linux上不起作用,因此您可能必须在服务器端进行一些调整,才能将其移到正确的位置.

Bear in mind that by default the file will get uploaded as the 'Filedata' parameter. Technically you could change that to 'user[photo]', but apparently that doesn't work on Linux, so you may have to do some shimmying on the server-side to move that into the right place.

这篇关于将Rails与Paperclip和SWFUpload一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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