阶段
图像画廊应用程序。我有两个模型Handcraft
和Photos
.
一个手工艺品可能有很多照片,假设我有这样的模型:
Handcraft(name:string)
Photo(filename:string, description:string, ...)
在_form.html.erb
手工艺品中,有:
<%= form_for @handcraft, html: {multipart: true} do |f| %>
# ... other model fields
<div class="field">
<%= f.label :photo %><br />
<%= f.file_field :photo %>
</div>
# ... submit button
<% end %>
handcraft.rb
看起来像这样:
class Handcraft < ActiveRecord::Base
attr_accessible :photo
has_many :photos
mount_uploader :photo, PhotoUploader
# ...
end
photo_uploader.rb
:
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_limit => [100, 100]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
问题
当我提交表单时,它会引发此错误:
NoMethodError (undefined method `photo_will_change!' for #<Handcraft:0xb66de424>):
问题
在这种情况下,我应该如何使用/配置 Carrierwave?