Get absolute URL for paperclip attachment

前端 未结 7 2276
长发绾君心
长发绾君心 2021-02-02 10:19

Is it possible to get the absolute URI for a Paperclip attachment? Right now, the problem is that the production environment is deployed in a sub-URI (on Passenger: RackBa

7条回答
  •  感动是毒
    2021-02-02 10:41

    You can add to your application.rb (or for specific enviroment in config/environments/*):

    config.paperclip_defaults = {
        url: "http://my.address.com/system/:class/:attachment/:id_partition/:style.:extension",
        path: ':rails_root/public/system/:class/:attachment/:id_partition/:style.:extension',
    }
    

    Restart and reimport your images.

    PS: obviously you can replace http://my.address.com with an environment variable.

提交回复
热议问题