Get absolute URL for paperclip attachment

前端 未结 7 2062
长发绾君心
长发绾君心 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:24

    The most widely applicable way of doing this is to first define your asset hosts in the relevant config/environment file:

    config.action_controller.asset_host = "http://assethost.com"
    config.action_mailer.asset_host = "http://assethost.com"
    

    Then in views and mailers:

    asset_url(model.attachment.url(:style))
    

    In the console:

    helper.asset_url(model.attachment.url(:style))
    

    In a model:

    ApplicationController.helpers.asset_url(model.attachment.url(:style))
    

提交回复
热议问题