jquery - Dropzone on Rails causing double form submission to DB -


when "save" button clicked, there 2 entries created. 1 :map information stored, , 1 missing it, both same :name. how complete entry save?

new.html.erb

<%=form_for [@location, @floor], html: {class: "dropzone", multipart: true, id: "map-upload"} |f|%>   <div>     <%=f.label :name%>     <%=f.text_field :name%>   </div>    <div class="fallback">     <%=f.label :map%>     <%=f.file_field :map%>   </div>    <%=f.submit "save", id: "floor-submit"%> <%end%> 

drag-drop.js

$(document).ready(function() {   // disable auto discover   dropzone.autodiscover = false;    var mapupload = new dropzone("#map-upload", {     paramname: "floor[map]",     autoprocessqueue: false,     maxfiles: 1,     addremovelinks: false,     dictdefaultmessage: 'drag & drop map image file here, or click here select file upload',   });    $('#map-upload').submit(function(e){     mapupload.processqueue();   }); }); 

relevant part of floor_controller:

  def create     @floor = current_user.company.locations.find(params[:location_id]).floors.create(floor_params)      if @floor.save       flash[:notice] = "floor has been created."       redirect_to location_floors_path     else       flash[:alert] = "there error saving floor, please try again"       render 'new'     end   end 

model

class floor < activerecord::base   belongs_to :location    has_attached_file :map   validates_attachment_content_type :map, :content_type => /\aimage\/.*\z/ end 

i think js submitting once , rails form submitting second time. recommend disabling 1 of them.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -