ruby on rails - CarrierWave version path -
i have model catagory
class category < activerecord::base mount_uploader :image, categoryimageuploader end
i need save image name (id saved category)
class categoryimageuploader < carrierwave::uploader::base include carrierwave::rmagick storage :file mounted: def store_dir #"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end def store_path(for_file = filename) "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}/#{for_file}" end version :small process resize_to_fit: [48, 48] def filename(uploaded_file = file) if uploaded_file.present? "small_#{model.id}.#{uploaded_file.extension}" end end end version :big process resize_to_fit: [200, 200] def filename(uploaded_file = file) if uploaded_file.present? "big_#{model.id}.#{uploaded_file.extension}" end end end def filename(uploaded_file = file) if uploaded_file.present? "#{model.id}.#{uploaded_file.extension}" end end # override filename of uploaded files: # avoid using model.id or version_name here, see uploader/store.rb details. # def filename # "something.jpg" if original_filename # end end
i'm use https://coderwall.com/p/mulldw/custom-file-names-with-carrierwave-and-amazon-s3 to save image this 3.png 4.png
version :small , version :big aslo save (like big_3.png small_3.png )
but
**category.last.image_url => "/uploads/category/image/10/10.png" category.last.image_url(:small) = > "/uploads/category/image/10/10.png" category.last.image_url(:big) = > "/uploads/category/image/10/10.png"**
all links lead 1 image 10.png
i need
**category.last.image_url => "/uploads/category/image/10/10.png" category.last.image_url(:small) = > "/uploads/category/image/10/small_10.png" category.last.image_url(:big) = > "/uploads/category/image/10/big_10.png"**
Comments
Post a Comment