Paperclip :: RegistrationsController#update中的错误处理缩略图时出错。
我正在运行Rails 4.2.6
和paperclip", "~> 5.0.0"
我的应用程序控制器文件是:
class NewsController < ApplicationController
def create
@news = News.new(news_params)
respond_to do |format|
if @news.save
format.html { redirect_to news_url, notice: 'News post was successfully created.' }
format.json { render :show, status: :created, location: @news }
else
format.html { render :new }
format.json { render json: @news.errors, status: :unprocessable_entity }
end
end
end
private
def news_params
params.require(:news).permit(:topic, :header, :content, :link, :image)
end
end
我的新闻模式是:
class News < ActiveRecord::Base
validates :image, presence: true
has_attached_file :image, styles: { thumb: "64x64#", small: "100x100#", med: "150x150#", large: "200x200# -adaptive-resize" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
我的回形针数据库迁移是:
class AddAttachmentImageToNews < ActiveRecord::Migration
def self.up
change_table :news do |t|
t.attachment :image
end
end
def self.down
remove_attachment :news, :image
end
end
数据库架构:
ActiveRecord::Schema.define(version: 20160809173534) do
create_table "news", force: :cascade do |t|
t.string "topic", limit: 255
t.string "header", limit: 255
t.string "content", limit: 255
t.string "link", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name", limit: 255
t.string "image_content_type", limit: 255
t.integer "image_file_size", limit: 4
t.datetime "image_updated_at"
end
end
当我rake db:migrate
这个然后尝试使用它时,我会得到Paperclip::Error in NewsController#create
There was an error processing the thumbnail for dfc9ea4994791a9884f662cfa4333da420160809-29993-12b0k3n
。
完整错误:
Started POST "/news" for 127.0.0.1 at 2016-08-09 13:47:40 -0400
Processing by NewsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"LQOcaS5Nfm63jIBRxjrDrjjrO/3yvKqdAgiwllPsyuZ2gQNbq4USbc+G5Nr6JuBqYZQdO6lFTHBdretDEk3Xrg==", "news"=>{"topic"=>"AutoCAD", "header"=>"News header 1", "content"=>"something should work eventually.", "link"=>"link here", "image"=>#<ActionDispatch::Http::UploadedFile:0x007fd568e25028 @tempfile=#<Tempfile:/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/RackMultipart20160809-47024-131c2mr.jpg>, @original_filename="blockhead.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"news[image]\"; filename=\"blockhead.jpg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"Create News"}
Linkpost Load (0.4ms) SELECT `linkposts`.* FROM `linkposts` ORDER BY title
Admin Load (0.3ms) SELECT `admins`.* FROM `admins` WHERE `admins`.`id` = 1 ORDER BY `admins`.`id` ASC LIMIT 1
Command :: file -b --mime '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-yckinl.jpg'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]'
Command :: convert '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]' -auto-orient -resize "x64" -crop "64x64+0+0" +repage '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/62af5247d7ae99288c3db01615055e6c20160809-47024-1vtevvl'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]'
Command :: convert '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]' -auto-orient -resize "x100" -crop "100x100+0+0" +repage '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/62af5247d7ae99288c3db01615055e6c20160809-47024-1ndlv2i'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]'
Command :: convert '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]' -auto-orient -resize "x150" -crop "150x150+0+0" +repage '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/62af5247d7ae99288c3db01615055e6c20160809-47024-1dpm4bl'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]' 2>/dev/null
Command :: identify -format %m '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]'
Command :: convert '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a.jpg[0]' -auto-orient -resize "200x200#" '/var/folders/y5/brmnsb2n4f5_mkpmmn_ll_280000gn/T/62af5247d7ae99288c3db01615055e6c20160809-47024-q1w9zr'
Completed 500 Internal Server Error in 815ms (ActiveRecord: 0.6ms)
Paperclip::Error (There was an error processing the thumbnail for dfc9ea4994791a9884f662cfa4333da420160809-47024-t1m52a):
app/controllers/news_controller.rb:28:in `create'
我之前有一个名为image的新闻类的属性,不确定是否会混淆任何东西?
这似乎是一个数据库问题,因为如果我做一个rake db:setup它工作正常。但是,我不想擦除我的数据库,因此这不是一个选项,因为db:setup
运行db:schema:load
这将删除服务器上的数据。
任何帮助或建议将不胜感激。感谢。
答案 0 :(得分:0)
在news
模型中更改了此行:
has_attached_file :image, styles: { thumb: "64x64#", small: "100x100#", med: "150x150#", large: "200x200# -adaptive-resize" }
对此:
has_attached_file :image, styles: { thumb: "64x64#", small: "100x100#", med: "150x150>", large: "200x200>" }
我猜测-adaptive-resize
混乱了,我必须找到一种不同的方法来调整图像大小而不会扭曲它。