Get absolute URL for paperclip attachment

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

    According to this github issue, it is cleaner to use ActionController::Base.asset_host so it would result the helper:

      def add_host_prefix(url)
        URI.join(ActionController::Base.asset_host, url)
      end
    

    This supposes you have in every /config/environments/.rb file the following:

    Appname::Application.configure do
    
      # ....
    
      config.action_controller.asset_host = 'http://localhost:3000' # Locally
    
      # ....
    
    end
    

提交回复
热议问题