Rails file_field不上传任何内容 [英] Rails file_field does not upload anything

查看:45
本文介绍了Rails file_field不上传任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Rails 4和Ruby 2与Carrier Wave以及jQuery Mobile 1.3一起使用,并且用户有一个带有徽标的配置文件。我已经在控制台中测试了后端载波波形的东西,并且可以正常工作。

I am using Rails 4 and Ruby 2 with Carrier Wave along with jQuery Mobile 1.3, and a user has a profile which has a logo. I have tested the backend Carrier Wave stuff in the console and it works.

问题出在表单帮助程序中,我做什么都无所谓,但有一个file_field将显示并让我选择一个图像,但它不会出现在参数中。如果我将其更改为不存在的字段,例如 = f.file_field:field_not_permitted_in_strong_params 如果我将其更改为 = f.text_field:field_not_permitted_in_strong_params ,它不会掉下来并且文件选择器可见。 code>,然后铁轨才会插入并抱怨该字段不存在。

The problem is in the form helper, it doesn't matter what I do, but a file_field will display and let me choose an image, but it does not come through in the params. If I change it to a field that does not exist eg. =f.file_field :field_not_permitted_in_strong_params it does not fall over and a file picker is visible, if I change that to =f.text_field :field_not_permitted_in_strong_params, only then does rails kick in and complain about the field not existing.

所以我的问题基本上是可以上传文件客户端的,但是它不会通过表单数据发送,也不会出现在params哈希中,并且我的所有其他字段都可以正常工作。

So my problem is basically, I can upload a file client side, but it does not get sent through in the form data, or appear in the params hash, and all my other fields work correctly.

这里是以下形式的代码段:

Here is a snippet of the form:

= form_for(@business_profile, :html => {:multipart => true}, :url => business_profile_path, :validate => true) do |f|

    =image_tag(@business_profile.logo.url, class: 'business-logo')
    %div{:data => {:role => 'fieldcontain'}}
        =f.file_field :logo

    - # Basic Information
    %div{:data => {:role => 'collapsible', :collapsed => 'false'}}
        %h3
            Basic Information                 
        %div{:data => {:role => 'fieldcontain'}}
            = f.label :name, 'Business name:' 
            = f.text_field :name
        %div{:data => {:role => 'fieldcontain'}}
            = f.label :address, 'Address:'
        = f.text_area :address, class: 'address'


推荐答案

在花了几个小时后确定,问题是jQuery Mobile默认使用Ajax提交表单,并且文件不能
因此解决方案是禁用Ajax,例如:

OK after spending hours on the matter, the problem is that jQuery Mobile submits forms with Ajax by default, and files cannnot be submitted with Ajax without using plugins etc. So the solution is to disable the Ajax like this:

= form_for(@business_profile, :url => business_profile_path, :validate => true, :html => { :'data-ajax' => false }) do |f|

这篇关于Rails file_field不上传任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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