Paperclip Gem Not Uploading Images

105 Views Asked by At

I have paperclip in several places throughout my application. I am trying to upload to attachments (two images) with one of my forms and it isn't providing any helpful information to as why It's not uploading successfully. I'm using paperclip 4.2.2.

The paperclip logs are as follows:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"XX", "listing_information_form"=>{"business_id"=>"11", "loan_id"=>"a09550000009thyAAA", "loan_name"=>"Growth!", "logo"=>#<ActionDispatch::Http::UploadedFile:0x007f8da1f4c3c0 @tempfile=#<Tempfile:/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/RackMultipart20150622-11918-kkeln9>, @original_filename="woods_logo.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"listing_information_form[logo]\"; filename=\"woods_logo.png\"\r\nContent-Type: image/png\r\n">, "loan_image"=>#<ActionDispatch::Http::UploadedFile:0x007f8da1f4c280 @tempfile=#<Tempfile:/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/RackMultipart20150622-11918-1sz4xkn>, @original_filename="woods_photo.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"listing_information_form[loan_image]\"; filename=\"woods_photo.jpeg\"\r\nContent-Type: image/jpeg\r\n">, "terms_acceptance"=>"1"}, "commit"=>"Next", "business_id"=>"11"}
  User Load (0.8ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 11  ORDER BY "users"."id" ASC LIMIT 1
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-1evafhf.png'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-obmo0e.png[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-obmo0e.png[0]'
Command :: convert '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-obmo0e.png[0]' -auto-orient -resize "90x90" '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-obmo0e20150622-11918-11miz6z'
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-obmo0e20150622-11918-11miz6z'
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-l8tqr6.jpeg'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-1x7oerq.jpeg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-1x7oerq.jpeg[0]'
Command :: convert '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-1x7oerq.jpeg[0]' -auto-orient -resize "310x202>" '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-1x7oerq20150622-11918-fhthka'
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-1x7oerq20150622-11918-fhthka'
   (0.3ms)  BEGIN
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-bnp8ul.png'
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-15i63c4.jpeg'
   (0.3ms)  ROLLBACK
   (0.1ms)  BEGIN
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-19ipmvb.png'
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-iso9kn.jpeg'
   (0.3ms)  ROLLBACK
   (0.2ms)  BEGIN
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/92aeff05601e4e4ad9aded985f07727020150622-11918-1vhhwhy.png'
Command :: file -b --mime '/var/folders/1f/95lf0jwd0wjbl6zkvmdyffyw0000gn/T/b631013baf68cc1bc1e1a9d5a80163d220150622-11918-abrbba.jpeg'
   (0.3ms)  ROLLBACK
Redirected to http://localhost:3000/businesses/12/listing_information_form/new
Completed 302 Found in 363ms (ActiveRecord: 1.9ms)

I just see the BEGIN/ROLLBACK attempts.

My controller code:

@listing_information_form = ListingInformationForm.create(listing_information_form_params)
if @listing_information_form.save && @listing_information_form.cancel_loan == nil
  redirect_to business_embedded_signing_path(@user)
elsif @listing_information_form.save && @listing_information_form.cancel_loan == true
  redirect_to business_root_path
else
  flash[:warning] = 'Unsuccessful'
  redirect_to :back
end

private

def listing_information_form_params
  params.require(:listing_information_form).permit(:business_id, :terms_acceptance, :logo_url, :picture_url, :business_profile, :loan_id, :loan_name, :logo, :loan_image, :cancel_loan)
end 

My model:

has_attached_file :logo,
    :styles => { :original => "90x90" },
    :storage => :s3, 
    :url => ":s3_domain_url",
    :path => "account/:class/:railsid/:filename"
has_attached_file :loan_image,
    :styles => { :original => "310x202>" },
    :storage => :s3, 
    :url => ":s3_domain_url",
    :path => "account/class/:railsid/:filename"

Can anyone provide some information on the trace being provided by Paperclip? I'm uploading these files to s3 and haven't had any issues on the other forms throughout my application.

1

There are 1 best solutions below

0
On

From the comments on the question...

What happens if you puts @listing_information_form.errors.to_yaml just before the redirect?

@Questifer's answer:

The to_yaml showed me the ridiculous error I should've been seeing. It had to do with the cancel_loan field. I really appreciate you helping me debug this- you saved me a lot of time and frustration.

Glad I could help! Sometimes just pecking at things with puts can be effective.

BONUS: My other suggestion would be to cache the value of save in a local variable like this so you don't accidentally run save twice:

@listing_information_form = ListingInformationForm.create(listing_information_form_params)
success = @listing_information_form.save

if success && @listing_information_form.cancel_loan == nil
  redirect_to business_embedded_signing_path(@user)
elsif success && @listing_information_form.cancel_loan == true
  redirect_to business_root_path
else
  flash[:warning] = 'Unsuccessful'
  redirect_to :back
end