如何通过activeadmin模式窗口上传文件

时间:2015-08-19 12:23:10

标签: javascript ruby-on-rails activeadmin

我想使用模态窗口上传文件,但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()

1 个答案:

答案 0 :(得分:0)

需要将表单编码为多部分:

$sql="SELECT toplist_id, name, SUM(points) as totalPoints
      FROM database_name
      GROUP BY name
      ORDER BY SUM(points) as totalPoint DESC";