weixin_33725722 2017-04-11 13:42 采纳率: 0%
浏览 19

上传文件ajax调用

I am trying to upload and render a csv via an ajax call, but I am receiving this error: "ActionController::UnknownFormat". What I am doing wrong ?

Controller:

class HomesController < ApplicationController
  def index
    @items = []
  end

  def upload
    myfile = params[:file]
    @items = CSV.read(myfile.path)
    respond_to do |format|
      format.js
    end
  end
end

View:

<%= form_tag(homes_upload_path, multipart: true, remote: true, :authenticity_token => true) do %>
  <%= file_field_tag :file %>
  <%= submit_tag( "Import" ) %>
<% end %>

<div>
  <div id="items_grid" >
    <%= render partial: 'items_list', locals: {items: @items}  %>
  </div>
</div>

upload.js.erb:

$("#items_grid").html("<%= escape_javascript(render partial: 'items_list', locals: { items: @items } ) %>");
  • 写回答

1条回答 默认 最新

  • ℡Wang Yan 2017-04-11 13:51
    关注

    Rails remote true does not support in case of attachments. Please use 'remotipart' gem for this functionality.

    gem 'remotipart', '~> 1.2'
    
    bundle install
    
    //= require jquery.remotipart
    

    Remotipart Gem

    评论

报告相同问题?

悬赏问题

  • ¥15 Develop a Python script
  • ¥15 global_max_fast,flags问题
  • ¥15 c#:vsto,powerpoint的外接程序中换主题颜色
  • ¥15 状态机/汽车转向灯/Sateflow
  • ¥15 这个有点复杂 有没有人看看
  • ¥15 用python如何确定子孙元素在父元素中的位置
  • ¥15 obj文件滤除异常高程
  • ¥15 用mathematicas或者matlab计算三重积分
  • ¥15 Loop unrolling的runtime计算
  • ¥100 NVMe-oF的Target端,开启attr_offload后,测试失败。