instance method asset_path

Ruby on Rails 4.2.9

Since v4.0.13

Available in: v4.0.13 v4.1.16 v4.2.9 v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

asset_path(source, options = {})

Computes the path to asset in public directory. If :type options is set, a file extension will be appended and scoped to the corresponding public directory.

All other asset *_path helpers delegate through this method.

asset_path "application.js"                     # => /assets/application.js
asset_path "application", type: :javascript     # => /assets/application.js
asset_path "application", type: :stylesheet     # => /assets/application.css
asset_path "http://www.example.com/js/xmlhr.js" # => http://www.example.com/js/xmlhr.js

Parameters

source req
options opt = {}
Source
# File actionview/lib/action_view/helpers/asset_url_helper.rb, line 123
      def asset_path(source, options = {})
        source = source.to_s
        return "" unless source.present?
        return source if source =~ URI_REGEXP

        tail, source = source[/([\?#].+)$/], source.sub(/([\?#].+)$/, '')

        if extname = compute_asset_extname(source, options)
          source = "#{source}#{extname}"
        end

        if source[0] != ?/
          source = compute_asset_path(source, options)
        end

        relative_url_root = defined?(config.relative_url_root) && config.relative_url_root
        if relative_url_root
          source = File.join(relative_url_root, source) unless source.starts_with?("#{relative_url_root}/")
        end

        if host = compute_asset_host(source, options)
          source = File.join(host, source)
        end

        "#{source}#{tail}"
      end

Defined in actionview/lib/action_view/helpers/asset_url_helper.rb line 123 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionView::Helpers::AssetUrlHelper

Type at least 2 characters to search.

↑↓ navigate · open · esc close