【发布时间】: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