ncuesta / dropzonejs-rails

Spice your Rails apps with some Dropzone sugar!
http://rubygems.org/gems/dropzonejs-rails
MIT License
311 stars 56 forks source link

ActionController::ParameterMissing in UploadsController#create param is missing or the value is empty: upload #36

Closed gbrl closed 7 years ago

gbrl commented 7 years ago

I created a basic scaffold called Upload, installed the gem with JS and CSS etc... added the class "dropzone" to my form, and when I drag and drop files, I get this error:

ActionController::ParameterMissing in UploadsController#create param is missing or the value is empty: upload

Does this gem not know how to create the params object properly? I thought it would know to submit the form in its entirety. It seems to be only uploading the one text_field.

Here is the log:

Started POST "/user/uploads" for ::1 at 2016-11-01 14:05:32 -0400
Processing by UploadsController#create as JSON
  Parameters: {"utf8"=>"āœ“", "authenticity_token"=>"XXX", "commit"=>"Save", "file"=>#<ActionDispatch::Http::UploadedFile:0x007ffdbbb9d528 @tempfile=#<Tempfile:/var/folders/ky/t_cjwg7n2dg58dpn86h_lhsw0000gn/T/RackMultipart20161101-5079-1jsf0qq.pdf>, @original_filename="jp.pdf", @content_type="application/pdf", @headers="Content-Disposition: form-data; name=\"file\"; filename=\"jp.pdf\"\r\nContent-Type: application/pdf\r\n">}

Here is my form:

= form_for @upload, :html => {:class => 'dropzone'} do |f|
  - if @upload.errors.any?
    #error_explanation
      %h2= "#{pluralize(@upload.errors.count, "error")} prohibited this upload from being saved:"
      %ul
        - @upload.errors.full_messages.each do |msg|
          %li= msg

    = f.hidden_field :name, value: "My CV", class: 'hidden'
  .field
    = f.label :my_cv, "My CV"
    %br
    = f.file_field :my_cv
  .actions
    = f.submit 'Save', class: 'hidden

I read in the docs that the default name for the file_field is "file". Could that be causing the problem? I thought this gem would read the form attributes and figure out what params to send.... Maybe I'm wrong. Please halp! LOL :)

Thanks for your time,

G

ncuesta commented 7 years ago

Hi @gbrl, just to clarify things a bit: this gem is a simple wrapper around Dropzone JS and its use on a Rails-based application. All this gem does is simplify to work needed to get Dropzone's assets into the Asset Pipeline. It makes no assumptions, no hidden changes to your code, nor it magically detects when you are sending a file with Dropzone (a JS/frontend utility) and gets things working šŸ˜›

Having said that, I recommend you take a look at the generated HTML for the form and see which names those fields are getting. From what I can infer based on the info you provided, your controller expects a upload parameter which isn't being sent from the client - you may need to check Dropzone's configuration to change the field names used when using the library for sending the files.

I'm closing this issue as this is not related to the gem itself, but feel free to ask any other questions if you should need further help.

Cheers!

gbrl commented 7 years ago

Ah OK. Maybe I'll fork and update the README.md when I get it working. Would be useful because all standard rails scaffold forms probably require the same solution. Thanks for the quick response!

ncuesta commented 7 years ago

That would be awesome! Thanks and good luck with that.