回形针宝石不上传图像

时间:2015-06-22 18:54:10

标签: ruby-on-rails paperclip

在整个申请过程中,我在几个地方都有回形针。我正在尝试使用我的某个表单上传到附件(两张图片),并且它没有提供任何有用的信息,因为它没有成功上传。我使用了paperclip 4.2.2。

回形针日志如下:

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)

我只看到BEGIN / ROLLBACK尝试。

我的控制器代码:

@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 

我的模特:

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"

任何人都可以提供有关Paperclip提供的跟踪的一些信息吗?我将这些文件上传到s3,并且在我的应用程序中没有其他表单上的任何问题。

1 个答案:

答案 0 :(得分:0)

从问题的评论......

  

如果您在重定向之前puts @listing_information_form.errors.to_yaml会发生什么?

@ Questifer的回答:

  

to_yaml向我展示了我应该看到的荒谬错误。它与cancel_loan字段有关。我真的很感谢你帮助我调试这个 - 你为我节省了很多时间和挫折。

很高兴我能帮到你!有时用puts啄食事物可能会有效。

BONUS:我的另一个建议是将save的值缓存在这样的局部变量中,这样您就不会意外地运行save两次:

@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