多部分表单在Rails中不起作用 [英] Multipart form not working in Rails

查看:78
本文介绍了多部分表单在Rails中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后一天,我一直在尝试在Rails中创建一个多部分的表单,这很疯狂,但是我真的不确定如何解决这一问题.

I have been trying to create a multi-part form in Rails for the last day, which is crazy, but I am really not sure how to get around this one.

当前,这是我认为的代码:

Currently, here is the code in my view:

<%= form_for @account, :html => {:multipart => true } do |f| %> 

但是,返回的HTML如下:

However, the HTML returned is as follows:

<form accept-charset="UTF-8" action="/accounts/1" class="edit_account" id="edit_account_1" method="post">

对于我的一生,我无法弄清楚为什么表格没有显示为多部分.该特定表单用于使用回形针将图像上传到AWS,但每次都会失败,大概是因为它不是多部分表单.

For the life of me I can't figure out why the form is not showing up as a multi-part. This particular form is used to upload an image using paperclip to AWS, but fails each time, presumably because it isn't a multipart form.

帮助! :)谢谢.

推荐答案

根据 Rails API v3.1.3 ,您的代码应如下所示:

Hi according to Rails API v3.1.3, your code should look like following:

 <%= form_for @account,{},:html => {:multipart => true } do |f| %> 

区别在于,将空选项传递给rails helper,它将读取您的html参数.

The difference is by passing empty options to rails helper and it will read your html parameters.

谢谢

更新:

这是从我的一个项目中复制的代码: 它正在运行并在Rails 3.1下运行.

Here is the code copied from one of my projects: It is working and runs under Rails 3.1

也许您可以尝试将括号放在"form_for"之后

May be you could try to put brackets after the "form_for"

<%= form_for(@account,{},:html => { :id=>"account_form",:multipart => true }) do |f| %>
  <%= render :partial => "form", :object => f %>
  <%= f.submit 'create' %>
<% end %>

这篇关于多部分表单在Rails中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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