我在Rails 4中使用Carrierwave而没有将其安装到特定型号 并尝试通过initialize方法传递我的属性,以便store_dir可以知道存储文件的位置。
class CustomFormUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
attr_reader :custom_form
def initialize(custom_form)
@custom_form = custom_form
end
def store_dir
"uploads/custom_form/#{custom_form.id}/"
end
version :thumb do
process :resize_to_fill => [64, 64]
end
end
当我运行该测试时:
let(:uploader) { CustomFormUploader.new(custom_form) }
before do
CustomFormUploader.enable_processing = true
uploader.store!(File.open(File.join(Rails.root, '/spec/fixtures/passport.jpg')))
end
context 'the thumb version' do
it 'should scale down an image to be exactly 64 by 64 pixels' do
uploader.thumb.should have_dimensions(64, 64)
end
end
然后从初始化
获得错误 ArgumentError: wrong number of arguments (2 for 1)
知道如何在不出错的情况下将属性传递给上传器吗?
答案 0 :(得分:0)
在controller.rb
中<style name="NgTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:dialogTheme">@style/NgDialogTheme</item>
<item name="android:alertDialogTheme">@style/NgAlertDialogTheme</item>
</style>
<style name="NgDialogTheme" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:background">@android:color/transparent</item>
<item name="android:windowTitleStyle">@style/NgWindowTitleStyle</item>
</style>
<style name="NgAlertDialogTheme" parent="@style/NgDialogTheme">
</style>
<style name="NgWindowTitleStyle" parent="android:TextAppearance.Holo.DialogWindowTitle">
<item name="android:background">#318d99</item>
<item name="android:textColor">#fff</item>
</style>
在my_uploader.rb
中uploader = MyUploader.new(special_var)
uploader.store!(params[:icon])