ga-dc / wdi5-project4

3 stars 0 forks source link

Automatically posting form is not passing values #118

Closed nbumbarger closed 9 years ago

nbumbarger commented 9 years ago

I am using a "form" which automatically posts when a file is dragged into it: http://www.dropzonejs.com/

My version looks like this (views/media_contents/index.html.erb):

<%= form_tag '/media_contents', method: :post, class: "dropzone", id: "media-dropzone" do %>
  <%= text_field_tag :lat %>
  <%= text_field_tag :lng %>
  <div class="fallback">
    <%= file_field_tag "media", multiple: true%>
  </div>
<% end %>

https://github.com/nbumbarger/img2map/blob/master/app/assets/javascripts/media_contents.js

I want to add calculations to the lat and lng fields before the post occurs so that they will be submitted with the form, but nothing seems to work.

here is my javascript: https://github.com/nbumbarger/img2map/blob/master/app/assets/javascripts/media_contents.js

In the first function, I try to use a listening event which fires when the file is loaded. here, I calculate the lat long and store it in the fields. my alerts prove that it is stored in the fields before the post event occurs, yet the fields are blank in the response.

In the second function, I try to attach the calculation to a "sending" event, which is supposed to fire right after the post is happening. this time, I append the values I want directly to the form data, since the hidden fields have already been filled in at this point. Again, I see no sign of the data in the post event. Any thoughts?

For testing purposes, here is an image with geolocation: https://dl.dropboxusercontent.com/u/7989543/image2.jpg

jrhorn424 commented 9 years ago

@nbumbarger it looks like you're not whitelisting the coords. Don't you need strong parameters set up in your controller? https://github.com/nbumbarger/img2map/blob/master/app/controllers/media_contents_controller.rb

nbumbarger commented 9 years ago

That may work for the second attempt where I append to the form. what would accept be in this case? just "coords"?

The oddity is that lat lon can be passed through the hidden field method, they're just blank on the first post even though the alert pauses the action and shows that they are updated. if I upload a second image, it submits with the coordinates that are left over from the first image.

jrhorn424 commented 9 years ago

Ah, that sounds like a turbolinks issue. Have you dealt with that yet? https://github.com/ga-dc/wdidc5-project3/issues/41