ruby on rails 3 - Carrierwave: set image path and skip the upload -


i set images without uploading. (they exist, or task saves them...)

if try (in rails console):

user = user.last user.picture = '/some/picture.jpg' user.save user.picture # nil 

the way set remote_picture_url, , delete upload (which stupid)

is there method in carrierwave lets modify filename ?

class user < activerecord::base   attr_accessible :picture   # don't want write database, want able check   attr_writer :skip    # set default value   def skip    @skip ||= false   end    mount_uploader :image, pictureuploader    # make sure skip callback comes after mount_uploader   skip_callback :save, :before, :store_picture!, if: :skip_saving?    # other callbacks might triggered depending on usecase   #skip_callback :save, :before, :write_picture_identifier, id: :skip_saving?    def skip_saving?     skip   end end  class pictureuploader < carrierwave::uploader::base   # implement filename=   def set_filename(name)     @filename = name   end end 

assuming have setup above, in console:

user = user.last user.picture.set_filename('/some/picture.jpg') user.skip = true # save skip callback store_picture! user.save user.picture # /some/picture.jpg 

it should noted if you're in console , update existing record has attached file (ie user.picture.file) show old url/location. if quit console (assuming you're not in sandbox mode) , come , query same object have updated url/location.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -