Get absolute URL for paperclip attachment

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

    This doesn't solve the original poster's problem exactly (it operates in the view, not the model), but may be helpful for people who are trying to "get absolute URL for paperclip attachment" within their view: In the same way that

    image_tag(user.avatar.url(:large))
    

    puts the image itself into your view,

    image_url(user.avatar.url(:large))
    

    returns just the URL you'll need if you want to link to the asset directly (e.g. in a link_to call).

提交回复
热议问题