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 } ) %>");