顯示具有 path 標籤的文章。 顯示所有文章
顯示具有 path 標籤的文章。 顯示所有文章

2008年12月2日 星期二

Adding a Directory to the Path, export, command

Adding a Directory to the Path

2008年10月12日 星期日

image_tag, path, url


http://api.rubyonrails.com/classes/ActionView/Helpers/AssetTagHelper.html


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 = Proc.new { |source| "http://assets#{rand(2) + 1}.example.com" }
image_tag("rails.png")
=> <img src="http://assets2.example.com/images/rails.png" alt="Rails" />
stylesheet_link_tag("application")
=> <link href="http://assets1.example.com/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />



ActionController::Base.asset_host = Proc.new { |source|
if source.starts_with?('/images')
"http://images.example.com"
else
"http://assets.example.com"
end
}
image_tag("rails.png")
=> <img src="http://images.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 = Proc.new { |source, request|
if request.ssl?
"#{request.protocol}#{request.host_with_port}"
else
"#{request.protocol}assets.example.com"
end
}

2008年8月29日 星期五

File, Pathname, Dir

http://www.ruby-doc.org/core/classes/File.html
http://www.ruby-doc.org/core/classes/Pathname.html
http://www.ruby-doc.org/core/classes/Dir.html#M002347

join, dirname, __FILE__, RAILS_ROOT, directory?

require File.join(File.dirname(__FILE__), 'boot')

RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)


>> File.directory?("#{RAILS_ROOT}/app")
=> true
>> File.exist?("#{RAILS_ROOT}/app")
=> true

>> File.exist?("#{RAILS_ROOT}/app/controllers/application.rb")
=> true
>> File.directory?("#{RAILS_ROOT}/app/controllers/application.rb")
=> false

Dir is file, too


Dir["config.?"] #=> ["config.h"]
Dir.glob("config.?") #=> ["config.h"]
Dir.glob("*.[a-z][a-z]") #=> ["main.rb"]
Dir.glob("*.[^r]*") #=> ["config.h"]
Dir.glob("*.{rb,h}") #=> ["main.rb", "config.h"]
Dir.glob("*") #=> ["config.h", "main.rb"]
Dir.glob("*", File::FNM_DOTMATCH) #=> [".", "..", "config.h", "main.rb"]