0

Please help me figure out what I am doing wrong here! I am using s3_direct_upload to upload a basic image to Amazon S3 and then POST to create a record. I can see in the Network tab (firebug) that it is being POST'd. However, I'm not sure why the params are not being added to the DB.

This is what I am getting back:

   Started POST "/choices" for 127.0.0.1 at 2013-10-02 17:36:10 -0700
   Processing by ChoicesController#create as */*
   Parameters: {"url"=>"https://mybucket.s3.amazonaws.com/uploads%2F1380760569802-bneiuk2ghf4-22e59d1c8959be731bc71e31f0a9d7c6%2Fslide0003_image002.jpg",        
   "filepath"=>"/uploads%2F1380760569802-bneiuk2ghf4-22e59d1c8959be731bc71e31f0a9d7c6%2Fslide0003_image002.jpg", 
   "filename"=>"slide0003_image002.jpg", 
   "filesize"=>"73930", 
   "filetype"=>"image/jpeg", 
   "unique_id"=>"bneiuk2ghf4", 
   "choice"=>{
      "image"=>"https://mybucket.s3.amazonaws.com/uploads%2F1380760569802-bneiuk2ghf4-22e59d1c8959be731bc71e31f0a9d7c6%2Fslide0003_image002.jpg"
    }
   }
   (0.3ms)  BEGIN
   (0.4ms)  ROLLBACK
  Rendered choices/create.js.erb (0.1ms)
  Completed 200 OK in 16ms (Views: 6.2ms | ActiveRecord: 0.6ms)

 

 # app/controllers/choice.rb
  def create
   @choice = Choice.create(choice_params)
  end

 def choice_params
   params.require(:choice).permit!
 end

Then my form (some HTML omitted for brevity):

#app/views/new.html.erb
   <%= s3_uploader_form callback_url: choices_url, callback_param: "choice[image]", id: "s3-uploader" do %>
      <%= file_field_tag :file, multiple: true %>
   <% end %>

Any help would be great!

1
  • What you Choise model expects on create? require only returns a {"image" => "https://..."} to you. Does your Choice model expect this single field? Your model is rolling back Commented Oct 3, 2013 at 18:07

1 Answer 1

1

From the 'ROLLBACK", It looks like you are not saving the record. Perhaps, some validations are not being met. Change

@choice = Choice.create(choice_params)

to

@choice = Choice.create!(choice_params)

So that you can get back information concerning why your record is not being saved.

Sign up to request clarification or add additional context in comments.

1 Comment

That was it. Validations were not being met; I forgot to remove an old unnecessary validation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.