简体   繁体   中英

Prevent carrierwave prepending `/uploads/`

Maybe I've got the wrong end of the stick here, but carrier wave appears to have an infuriating feature where it prepends /uploads/ to the attribute an uploader is mounted to:

Observe:

<%= debug attachment %>

--- !ruby/object:PostAttachment
attributes:
  id: 27
  post_id: 75
  avatar: xoCXDRSa911peGZ4lFJ7cQ==.gif
  created_at: 2014-04-01 02:38:03.197465000 Z
  updated_at: 2014-04-01 02:38:03.197465000 Z

The avatar is what I want to access, and yet when I do this:

<%= attachment.avatar %>

I get this:

 /uploads/xoCXDRSa911peGZ4lFJ7cQ%3D%3D.gif

Argh! Obviously I could gsub! that /uploads/ away but is there a configuration i can set?

 class MyUploader < CarrierWave::Uploader::Base def store_dir 'public/my/upload/directory' end end 

This works for the file storage as well as Amazon S3 and Rackspace Cloud Files. Define store_dir as nil if you'd like to store files at the root level.

From the Carrierwave Github page

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM