简体   繁体   English

Rails file_field不上传任何内容

[英]Rails file_field does not upload anything

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. 我正在将Rails 4和Ruby 2与Carrier Wave以及jQuery Mobile 1.3一起使用,并且用户有一个带有徽标的配置文件。 I have tested the backend Carrier Wave stuff in the console and it works. 我已经在控制台中测试了后端载波波形素材,并且可以正常工作。

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. 问题出在表单帮助程序中,我做什么都没关系,但是将显示一个file_field并让我选择一个图像,但是它不会在参数中出现。 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. =f.file_field :field_not_permitted_in_strong_params它不会掉下来,并且文件选择器是可见的,如果我将其更改为=f.text_field :field_not_permitted_in_strong_params ,则只有轨=f.text_field :field_not_permitted_in_strong_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. 所以我的问题基本上是,我可以上传文件客户端,但是不会通过表单数据发送出去,也不会出现在params哈希中,并且我的所有其他字段都可以正常工作。

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提交文件。因此,解决方案是禁用Ajax,如下所示:

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

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

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