【问题标题】:Is it possible to have 2 differnt file select fileds in transloadit form?是否可以在 transloadit 表单中有 2 个不同的文件选择字段?
【发布时间】:2013-12-19 10:46:34
【问题描述】:

所以,我有一个模型(在 rails 项目中),它有一个 logo 和一个封面图片,我想使用一个表单来上传它们,这可能与 transloadit 有关吗?我在任何地方都找不到示例...

【问题讨论】:

    标签: ruby-on-rails upload transloadit


    【解决方案1】:

    这是来自我的项目。我用了6次。希望对你有帮助。。

    new.html.haml

    - title t('.new_provider')
    .spacer
    .row
      .span12
        = render 'shared/flash_messages'
        %h1= yield :title
    .row
      .span12
        = bootstrap_form_for @provider, validate: true, html: {edit: "false", id: "providerform", enctype:"multipart/form-data", class: 'form-horizontal' } do |f|
          = transloadit_jquerify :providerform, :wait => true, :modal=>false
          = f.error_messages
          = render 'form', f: f
          .form-actions
            = f.submit t('.create'), id: 'provider_submit', class: 'btn btn-large btn-primary', disable_with: t('helpers.disable_with')
    = render 'providers/modal_phone_verification' 
    

    _form.html.haml

      = f.text_area :business_description, :id =>"business_description", :rows => "4"
      .controls
        %p.help-block{style:"margin-bottom: 15px; margin-top: -20px;"}
          %small
            = t('business_description_placeholder') 
      .control-group
        = label_tag :business_photos, t('.business_photos'), class: 'control-label'
        .controls
          = render partial: 'file_upload', :locals => {f: f}
          %span#file-error.help-inline{style: "display:none;color: #b44337"}=t('.file_presence_error')  
      .control-group
        .controls
          %p.help-block{style:"margin-bottom: 0px; margin-top: -20px;"} 
            %small
              = t('image_info')  
    

    _file_uplaod.html.haml

    = transloadit :image_resize
    -6.times do |index|
      .fileupload.fileupload-new.pull-left{style: "padding-right: 5px;", "data-provides" => "fileupload" }
        .fileupload-new.thumbnail{:style => "width: 130px; height: 130px;"} 
          -if @provider.provider_images.present?
            - if @provider.provider_images["provider_image#{index+1}"].present?
              %img{:id=>"providerimage1", :src => @provider.provider_images["provider_image#{index+1}"][0]}/
        .fileupload-preview.fileupload-exists.thumbnail{:style => "width: 130px; height: 130px;"}
        %div
          %span.btn.btn-file
            %span.fileupload-new{:id => "selectbutton"}
              -if index == 0
                =t('select_profile_image')  
              -else
                =t('select_image')              
            %span.fileupload-exists
              -if index == 0
                =t('select_profile_image')  
              -else
                =t('select_image')      
            =file_field_tag "provider_image#{index+1}", accept: 'image/png,image/bmp,image/jpeg,image/tif,image/jpg', :onchange =>"validateImageFiles(this);", :data => {:max_file_size => 5.megabytes}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-14
      • 1970-01-01
      • 2011-06-08
      • 1970-01-01
      相关资源
      最近更新 更多