How to override where images are stored by CarrierWave? def store_dir doesn't seem to work
I'm moving from attachment_fu to carrierwave, since attachment_fu is broken with Rails 3, and would like to be able to use the attachment_fu image files that I already have, instead of carrierwave making new ones and moving them somewhere else.
My images are partitioned by id, so if the user id is 61
and they upload a file called "foo.png"
, then their old attachment_fu image would be at "public/images/users/0000/0061/foo.png"
In my开发者_C百科 users model, I mount the carrierwave image uploader with:
attr_accessible :user_avatar
mount_uploader :user_avatar, UserAvatarUploader
In my UserAvatarUploader
, I have this:
def store_dir
File.join Rails.root, "public/images/users", ("%08d" % model.id).scan(/\d{4}/).join("/")
end
so when I set :user_avatar
, I should get "public/images/users/0000/0061/foo.png"
but when I try to set the :user_avatar
in the User
model to the old image
user.user_avatar = "#{Rails.root}/public/images/users/0000/0061/foo.png"
it comes back as something like "/uploads/tmp/20110916-1244-15398-7724/foo.png"
It seems that store_dir
is not being overwritten properly. What do I need to do to make this work right?
Carrierwave default base location is the public folder
try to change it by using
CarrierWave.configure do |config|
config.root = Rails.root
end
精彩评论