0

在本地一切正常,但在部署到 Heroku 后,我无法上传任何照片。这是heroku日志。我已经运行了 heroku rake db:migrate 并且已经根据carrierwave wiki设置了缓存目录,但我不确定如何解决这个问题。

2013-03-15T08:11:39+00:00 app[web.1]: Started POST "/posts" for xx.xx.xx.xx
 at 2013-03-15 08:11:39 +0000
2013-03-15T08:11:39+00:00 app[web.1]:
2013-03-15T08:11:39+00:00 heroku[router]: at=info method=POST path=/posts h
ost=boiling-bastion-xxxx.herokuapp.com fwd="xx.xx.xx.xx" dyno=web.1 queue=0 wait
=0ms connect=2ms service=1847ms status=500 bytes=643
2013-03-15T08:11:39+00:00 app[web.1]:
2013-03-15T08:11:39+00:00 app[web.1]: NoMethodError (undefined method `image_wil
l_change!' for #<Post:0x00000005ab1698>):
2013-03-15T08:11:39+00:00 app[web.1]:
2013-03-15T08:11:39+00:00 app[web.1]:   app/controllers/posts_controller.rb
:6:in `create'
2013-03-15T08:11:39+00:00 app[web.1]:
2013-03-15T08:11:39+00:00 app[web.1]: Completed 500 Internal Server Error in 11m
s
2013-03-15T08:11:39+00:00 app[web.1]: Processing by PostsController#create
as HTML
2013-03-15T08:11:39+00:00 app[web.1]:   Parameters: {"utf8"=>"???", "authenticit
y_token"=>"rR7KrBprIx=", "post"=>{"content
"=>"test", "image"=>#<ActionDispatch::Http::UploadedFile:0x00000005ac28a8 @origi
nal_filename="423366.jpg", @content_type="image/jp
eg", @headers="Content-Disposition: form-data; name=\"post[image]\"; filena
me=\"423366.jpg\"\r\nContent-Type: image/jpeg\r\n"
, @tempfile=#<File:/tmp/RackMultipart20130315-2-1mskj82>>}, "commit"=>"Post"}

ImageUploader 类

class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end
def extension_white_list
     %w(jpg jpeg gif png)
   end
def filename
     "#{secure_token(10)}.#{file.extension}" if original_filename.present?
   end

   def cache_dir
    "#{Rails.root}/tmp/uploads"
  end

我的 schema.db

create_table "posts", :force => true do |t|
    t.text     "content"
    t.integer  "user_id"
    t.datetime "created_at",      :null => false
    t.datetime "updated_at",      :null => false
    t.string   "image"
    t.text     "commentcontent"
    t.text     "comment_content"
  end
4

1 回答 1

1

imagePost.

我相信你有类似的东西:

class Post < ActiveRecord::Base
  mount_uploader :image, ImageUploader
end

因此,您需要创建迁移以添加image列:

rails g migration AddImageToPosts image:string

最后,

rake db:migrate
于 2013-03-15T09:52:02.277 回答