Stage
Image a gallery application.
I have two models Handcraft
and Photos
.
One handcraft may have many photos, suppose I have models like this:
Handcraft(name:string)
Photo(filename:string, description:string, ...)
In _form.html.erb
of handcrafts, there is:
<%= 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
looks like this:
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
Problem
When I submit form, it throws this error:
NoMethodError (undefined method `photo_will_change!' for #<Handcraft:0xb66de424>):
Question
How should I use/configure Carrierwave in this case?