【发布时间】:2016-12-15 14:28:12
【问题描述】:
Paperclip::Error in 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 这将删除服务器上的数据。
任何帮助或建议将不胜感激。谢谢。
【问题讨论】:
-
您可以将 :image 更改为 :picture 并使用它吗?但我建议不要同时保留两者。最好先删除以前的 :image 列。然后再次运行 rails paperclip news :image。
-
@loloso 我会试试的,谢谢。我应该如何删除
:image?我应该直接在终端中通过mysql吗?或者使用 Rails 迁移来删除列(我从未做过,但听说过)? -
使用 rails g migration remove_image_from_news image:attachment(或任何图像 -check db schema),这将在文件夹 db/migrate 中生成迁移。检查以确保它说从新闻中删除列(它是新闻,对吗??)。然后 rake db:migrate。然后检查架构以确保新闻表没有图像列。然后运行我上面有你的回形针生成器。现在很难用手机写信向您展示迁移的具体情况,但如果您遇到问题,请告诉我。
-
@loloso 不幸的是仍然得到相同的
Paperclip::Error... -
你能发布完整的错误吗?
标签: mysql ruby-on-rails paperclip image-uploading