Full url for an image-path in Rails 3

前端 未结 9 1495
说谎
说谎 2020-12-13 09:14

I have an Image, which contains carrierwave uploads:

Image.find(:first).image.url #=> \"/uploads/image/4d90/display_foo.jpg\"

In my vie

9条回答
  •  Happy的楠姐
    2020-12-13 09:38

    Just taking floor's answer and providing the helper:

    # Use with the same arguments as image_tag. Returns the same, except including
    # a full path in the src URL. Useful for templates that will be rendered into
    # emails etc.
    def absolute_image_tag(*args)
      raw(image_tag(*args).sub /src="(.*?)"/, "src=\"#{request.protocol}#{request.host_with_port}" + '\1"')
    end
    

提交回复
热议问题