Carrierwave 在控制台上给出错误
Carrierwave giving error on console
我在我的 rails 应用程序中安装了 carrierwave gem。
我的上传者class
class VoiceUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
我的模型class
require 'carrierwave/orm/activerecord'
class PulseFeedback < ActiveRecord::Base
belongs_to :tablet
mount_uploader :voice, VoiceUploader
end
但是每当我在 rails 控制台中使用存储方法时,我都会收到此错误。
2.2.0 :001 > v = VoiceUploader.new
=> #<VoiceUploader:0x000000038dc8b0 @model=nil, @mounted_as=nil>
2.2.0 :002 > v.store!("/home/raghu/Music/ajeeb.mp3")
CarrierWave::FormNotMultipart: CarrierWave::FormNotMultipart
from /home/raghu/.rvm/gems/ruby-2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/cache.rb:120:in `cache!'
from /home/raghu/.rvm/gems/ruby-2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/store.rb:56:in `store!'
我也不明白为什么模型和安装是零,即使我在我的模型中定义了安装器class
你应该存储一个文件,而不是一个字符串
class VoiceUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads"
end
end
v = VoiceUploader.new
File.open("/home/raghu/Music/ajeeb.mp3") do |f|
v.store!(f)
end
或者尝试为此使用模型
PulseFeedback.create({
voice: File.open("/home/raghu/Music/ajeeb.mp3")
})
我在我的 rails 应用程序中安装了 carrierwave gem。
我的上传者class
class VoiceUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
我的模型class
require 'carrierwave/orm/activerecord'
class PulseFeedback < ActiveRecord::Base
belongs_to :tablet
mount_uploader :voice, VoiceUploader
end
但是每当我在 rails 控制台中使用存储方法时,我都会收到此错误。
2.2.0 :001 > v = VoiceUploader.new
=> #<VoiceUploader:0x000000038dc8b0 @model=nil, @mounted_as=nil>
2.2.0 :002 > v.store!("/home/raghu/Music/ajeeb.mp3")
CarrierWave::FormNotMultipart: CarrierWave::FormNotMultipart
from /home/raghu/.rvm/gems/ruby-2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/cache.rb:120:in `cache!'
from /home/raghu/.rvm/gems/ruby-2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/store.rb:56:in `store!'
我也不明白为什么模型和安装是零,即使我在我的模型中定义了安装器class
你应该存储一个文件,而不是一个字符串
class VoiceUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads"
end
end
v = VoiceUploader.new
File.open("/home/raghu/Music/ajeeb.mp3") do |f|
v.store!(f)
end
或者尝试为此使用模型
PulseFeedback.create({
voice: File.open("/home/raghu/Music/ajeeb.mp3")
})