【问题标题】:how to upload file through activeadmin modal window如何通过activeadmin模式窗口上传文件
【发布时间】:2015-08-19 12:23:09
【问题描述】:

我想使用模态窗口上传文件,但是activeadmin模态模块不支持。

所以我更改了activeadmin的源文件,实际上是/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee

ActiveAdmin.modal_dialog = (message, inputs, callback)->
  html = """<form id="dialog_confirm" title="#{message}"><ul>"""
  for name, type of inputs
    if /^(datepicker|checkbox|text)$/.test type
      wrapper = 'input'
    else if type is 'textarea'
      wrapper = 'textarea'
    else if $.isArray type
      [wrapper, elem, opts, type] = ['select', 'option', type, '']
    else
      throw new Error "Unsupported input type: {#{name}: #{type}}"

我添加将代码if /^(datepicker|checkbox|text)$/.test type更改为

if /^(datepicker|checkbox|text|file)$/.test type

然后它可以显示文件形式,但我无法获取参数,有人可以帮忙吗?

这是我的代码:

$('a.upload').click (event) ->
    event.preventDefault()
    ActiveAdmin.modal_dialog "send file", choose_file: "file",
      (inputs)=> 
        if inputs.choose_file == ""
          alert "!!!"
        else
          $.post $(@).attr("href"),
            {
              choose_file: inputs.choose_file
            }, (data) ->
              window.location.reload()

【问题讨论】:

    标签: javascript ruby-on-rails activeadmin


    【解决方案1】:

    表单需要编码为多部分:

    html = """<form id="dialog_confirm" title="#{message}" enctype="multipart/form-data"><ul>"""
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 2021-06-06
      • 2017-07-07
      • 2014-07-23
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      相关资源
      最近更新 更多