没有从remotipart的提交后执行Javascript



我是一名新手RoR程序员,在使用remotipart上传文件并将其与POST请求一起提交给控制器后,我目前正在尝试使我的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 %>

您需要将此行添加到您的app/views/layouts/application.html.erb 中

<%= javascript_include_tag "application" %>

最新更新