Full url for an image-path in Rails 3

前端 未结 9 1500
说谎
说谎 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条回答
  •  爱一瞬间的悲伤
    2020-12-13 09:55

    You can also set CarrierWave's asset_host config setting like this:

    # config/initializers/carrierwave.rb
    CarrierWave.configure do |config|
      config.storage = :file
      config.asset_host = ActionController::Base.asset_host
    end
    

    This ^ tells CarrierWave to use your app's config.action_controller.asset_host setting, which can be defined in one of your config/envrionments/[environment].rb files. See here for more info.

    Or set it explicitly:

      config.asset_host = 'http://example.com'
    

    Restart your app, and you're good to go - no helper methods required.

    * I'm using Rails 3.2 and CarrierWave 0.7.1

提交回复
热议问题