Rails 3.1 absolute URL to an image

前端 未结 7 838
孤街浪徒
孤街浪徒 2020-12-08 14:27

I\'m using Rails 3.1. I\'m trying to figure this out, and to my surprise, it is starting to seem that rails does not come with this method at all. Maybe im wrong.

Ca

7条回答
  •  [愿得一人]
    2020-12-08 14:45

    put this in application_helper.rb

    def asset_url asset
      "#{request.protocol}#{request.host_with_port}#{asset_path(asset)}"
    end
    

    then you can use asset_url in your views.

提交回复
热议问题