我尝试在app / uploader中添加Picture Uploader但是在加载我的应用时出现此错误:
uninitialized constant Car::PictureUploader on line 3 of car.rb
应用/模型/ car.rb
class Car < ActiveRecord::Base
belongs_to :user
mount_uploader :picture, PictureUploader
validates :user_id, presence: true
validates :year, presence:true, length: { maximum: 4 }
validates :brand, presence:true
应用/上传/ picture_uploader.rb
class PictureUploader < CarrierWave::Uploader::Base
storage :file
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Add a white list of extensions which are allowed to be uploaded.
def extension_white_list
%w(jpg jpeg gif png)
end
end
在相当于picture_uploader.rb的文件没有在正确的文件夹中之前我已经收到此错误,但我认为这里的一切都是正常的。当我在user.rb中注释第3行时,页面加载。关于如何让我的页面运行的任何想法?
答案 0 :(得分:2)
有同样的错误,不得不手动终止服务器进程:
ps aux | grep server
kill [server process id]
出于某种原因,之前使用Ctrl + C关闭服务器似乎没有用。
答案 1 :(得分:1)
我想你想要:
::PictureUploader
其中指定它只是类PictureUploader
而不是命名空间PictureUploader
中的类Car
。
答案 2 :(得分:0)
只需重新启动服务器即可。它将解决此问题。在您的代码中一切正常。