Rails源代码分析(49):ActionView::Helpers::AssetTagHelper

Usage:

 1) using asset hosts

 

 

       ActionController::Base.asset_host = "assets.example.com"

       image_tag("rails.png")

         => <img src="http://assets.example.com/images/rails.png" alt="Rails" />

       stylesheet_link_tag("application")

         => <link href="http://assets.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />

 

       ActionController::Base.asset_host = "assets%d.example.com"

       

       ActionController::Base.asset_host = Proc.new { |source| "http://assets#{rand(2) + 1}.example.com" }

 

 2) using asset timestamps

       rails will append all assets with the asset's timestamp

       note that in order for this to work, all your application servers must return the same timestamps. This means that they must their clocks synchronized. To avoid the request for assets over and over again from a random host.

 

Code Reading:

 

      ASSETS_DIR      = defined?(Rails.public_path) ? Rails.public_path : "public" # check the asset dir is setup

      

      JAVASCRIPTS_DIR = "#{ASSETS_DIR}/javascripts" # the convention js dir

      STYLESHEETS_DIR = "#{ASSETS_DIR}/stylesheets" # the convention css dir

 

 

 1) auto_discovery_link_tag(type = :rss, url_options = {}, tag_options = {})

    

 

 

     # Returns a link tag that browsers and news readers can use to auto-detect an RSS or ATOM feed.

 

 2)  javascript_path(source)

      

     compute_public_path(source, 'javascripts', 'js')

     # Computes the path to a javascript asset in the public javascripts directory. if source has no extension, '.js' will be appended.

 

 

      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值