自己在做一个 demo 来学习 ror,之前部署在 heroku 一直好好的,然后昨天学习了 carrierwave 的使用。在本地一切都 ok,但 push 到 heroku 之后,打开 demo 地址,发现无法加载,使用heroku logs
, 报错:
/app/app/models/article.rb: 9: in `class:Article': uninitialized constant Article::PictureUploader (NameError).
之后发现无论是heroku run rails s
还是heroku run rails c
都是报这个错误。我不太明白,为和本地可以良好运行而远程就不行?故求助。
app/uploaders/picture_uploader.rb
class PictureUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
process resize_to_limit: [600, 600]
storage :qiniu
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def extension_white_list
%w{jpg gif png jpeg}
end
end
app/models/article.rb
class Article < ActiveRecord::Base
belongs_to :user
has_many :comments, dependent: :destroy
has_many :likes
validates :title, presence: true, length: {maximum: 50}
validates :content, length: {minimum: 10}
self.per_page = 10
attr_accessor :floor_number
mount_uploader :picture, PictureUploader
validate :picture_size
def picture_size
if picture.size > 5.megabytes
errors.add(:picture, "should be less than 5MB")
end
end
end