Ruby on rails 将文件上载到父级';s文件夹(Carrierwave+;s3)

Ruby on rails 将文件上载到父级';s文件夹(Carrierwave+;s3),ruby-on-rails,amazon-s3,carrierwave,Ruby On Rails,Amazon S3,Carrierwave,我有一个模型“图像”与一个上传连接到它。图像属于多个模型。我正在使用s3托管我的文件 现在我的路径是:“image/file.jpg” 上传图像后,我希望路径为“parent model/image/file.jpg”。我怎样才能做到这一点 谢谢 文件上传器.rb def store_dir "#{model.class.to_s.underscore}" end class Image < ActiveRecord::Base belongs_to :i

我有一个模型“图像”与一个上传连接到它。图像属于多个模型。我正在使用s3托管我的文件

现在我的路径是:“image/file.jpg”

上传图像后,我希望路径为“parent model/image/file.jpg”。我怎样才能做到这一点

谢谢

文件上传器.rb

   def store_dir
      "#{model.class.to_s.underscore}"
   end
class Image < ActiveRecord::Base
    belongs_to :imageable, :polymorphic => true

    mount_uploader :file, FileUploader
end
image.rb

   def store_dir
      "#{model.class.to_s.underscore}"
   end
class Image < ActiveRecord::Base
    belongs_to :imageable, :polymorphic => true

    mount_uploader :file, FileUploader
end
类映像true
装载上传器:文件,文件上传器
终止

要将文件上载到正确的目录,您需要将
存储目录
方法更改为

def store_dir
  "#{model.imageable.class.to_s.underscore"/images/"
end
甚至可能

"#{model.imageable_type.underscore"/images/"

(你需要尝试第二种方法,如果之前关联一直存在,应该可以使用。)

你现在得到了什么结果?现在我的路径是:“image/file.jpg”@MichalSzyndelYes,因为这是你要求Carrierwave做的事!)