2014.05.13 更新 该问题纯属自己粗心,犯了“下意识认为这部分没有问题”的错误,再次证明“你以为的并不一定就是你以为的那样”。 自己发现的结果在 #6 楼。惭愧!
——————————————————
操作员授权,以及 config/initializers/carrierwave.rb
配置都没有问题。
def image_data=(image_base64) unless image_base64.blank? data = StringIO.new(Base64.decode64(image_base64)) data.class.class_eval { attr_accessor :original_filename, :content_type } data.original_filename = self.email + '.jpg' data.content_type = 'image/jpg' self.avatar = data end end end
ImageUploader 是参考 @huacnlee 的 《[在 Rails 项目里面使用又拍云用于存储上传图片](http://huacnlee.com/blog/rails-app-image-store-with-carrierwave-upyun/#use-carrierwave)》 写的。
另外参考了帖子 《[关于又拍云的使用,undefined method 'uploader_secure_token'](http://ruby-china.org/topics/7132)》 也没有找到解决办法。
### 错误日志片段
D, [2014-05-10T14:47:28.897501 #67546] DEBUG -- : (BaseUploader.filename) bd3fdea8563a401c8b0accd61dd23a31
E, [2014-05-10T14:47:28.898015 #67546] ERROR -- : Binary data inserted for string
type on column password_digest
D, [2014-05-10T14:47:28.898240 #67546] DEBUG -- : SQL (0.1ms) INSERT INTO "auths" ("avatar", "created_at", "nickname", "password_digest", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?) [["avatar", "bd3fdea8563a401c8b0accd61dd23a31.jpg"], ["created_at", "2014-05-10 06:47:28.897638"], ["nickname", "foobar1"], ["password_digest", "$2a$10$/NJLntYAY2pZiZ.06zkTPusCZa5g0vcRKPm93BmEBCGv9XIX1FAwO"], ["updated_at", "2014-05-10 06:47:28.897638"], ["user_id", 33]]
D, [2014-05-10T14:47:28.898455 #67546] DEBUG -- : (BaseUploader.filename) bd3fdea8563a401c8b0accd61dd23a31
D, [2014-05-10T14:47:30.463842 #67546] DEBUG -- : (6.4ms) rollback transaction
I, [2014-05-10T14:47:30.464289 #67546] INFO -- : Completed 500 Internal Server Error in 1645ms
F, [2014-05-10T14:47:30.466549 #67546] FATAL -- :
RestClient::Unauthorized (401 Unauthorized):
app/controllers/users_controller.rb:47:in `create'
__这个问题我Google了半天,在stackoverflow上看了好几个相关的问题,都没有找到解决办法,烦请各位帮忙看看,谢谢!__