I have a Rails 4 form that is submitted via ajax by using :remote => true
. The response is JSON. I get redirected to a new page with the JSON instead of being left on the current page. Why does this happen?
The form:
<%= form_tag(
{:controller => :uploads, :action => :create},
:remote => true,
:authenticity_token => true,
multipart: true,
class: "hidden",
id: "uploadDataForm") do %>
<%= file_field_tag :file, class: "btn btn-primary btn-lg", style: "width: 100%;" %>
<%= submit_tag "Upload CSV", class: "btn btn-success btn-lg disabled" %>
<% end %>
The controller:
class UploadsController < ApplicationController
def create
@test = "hello"
render json: @test
end
end