paperclip custom :path and :url

前端 未结 2 1885
甜味超标
甜味超标 2020-12-31 16:08

I have some problems trying to custom the :path and :url options for has_attached_file with paperclip:

I have a polymorphic class named \"Asset\" that have :

相关标签:
2条回答
  • 2020-12-31 17:01

    Something like this in the url:

    :url => "/attachments/:path/:basename_:style.:extension",  
    

    then in the interpolations:

    Paperclip.interpolates :path do |attachment, style|
      if attachment.instance.file_owner_type == User.class.name
        # first set the _user variable (something like self.owner.id.to_s) 
        return "user_" + _user
      else
        # first set the _user, _dressing, _garmet, _category variables from your models
        return "user_#{_user}/dressing_#{_dressing}/garment_#{_garmet}/category_#{_category}/"
      end
    end
    

    Notice that you need to set the _user, _dressing, _garmet, _category variables from your models.

    Hope this helps.

    0 讨论(0)
  • 2020-12-31 17:03

    Try: attachment.instance.file_owner.class.downcase in your defined interpolation.

    0 讨论(0)
提交回复
热议问题