我正在尝试通过ajax调用上传和呈现csv,但我收到此错误:" ActionController :: UnknownFormat"。我做错了什么?
控制器:
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
查看:
<%= 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 } ) %>");
答案 0 :(得分:1)
Rails remote true不支持附件。请使用'remotipart'gem来实现此功能。
gem 'remotipart', '~> 1.2'
bundle install
//= require jquery.remotipart