我是一名新的 RoR 程序员,在我使用 remotipart 上传文件并将其与 POST 请求一起提交给 Controller 后,我目前正试图让我的 js 工作。基本上,单击提交按钮后,POST 请求已成功发送,但 parse_bond_file.js.erb 是作为 OTHER 而不是 SCRIPT 启动的。这是我的代码:
---upload.html.erb###
<%= form_for :parse_bond, :url => parse_bond_file_issuers_path, :html => { :multipart => true, :method => :post }, :remote => true do |f| %>
<%= f.file_field :csv %>
<%= f.submit 'Parse'%>
<% end %>
---issuer_controller.rb---
def parse_bond_file
respond_to do |format|
format.js
end
end
---parse_bond_file.js.erb---
alert('hello world!');
请帮忙。谢谢!
最佳答案
有了最新的remotipart,你需要把它包起来
<%= remotipart_response do %>
console.log('hellow world!');
<% end %>
关于Javascript 未从 remotipart 的提交后执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9090439/