ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
顯示具有
format
標籤的文章。
顯示所有文章
顯示具有
format
標籤的文章。
顯示所有文章
2008年12月10日 星期三
wbr,scan,regexp,$',$&,format
scan
wbr
=begin
a = "cruel world"
a.scan(/\w+/) #=> ["cruel", "world"]
a.scan(/.../) #=> ["cru", "el ", "wor"]
a.scan(/(...)/) #=> [["cru"], ["el "], ["wor"]]
a.scan(/(..)(..)/) #=> [["cr", "ue"], ["l ", "wo"]]
$` before match string
$' after match string
$& entire match string
=end
>> "111111222222333".scan(/....../).push($')
=> ["111111", "222222", "333"]
def wbr_by_6(long_word)
if long_word.chars.size > 6
long_word.scan(/....../).push($').map{|m| CGI.escapeHTML(m)}.join('
')
else
CGI.escapeHTML(long_word)
end
end
def format_content(content)
def sub_url(text)
if text =~ URI.regexp && $&[0,4] == 'http'
"#{$`}
#{wbr_by_6($&)}
#{sub_url($')}"
else
#content = CGI.escapeHTML(content)
wbr_by_6(text)
end
end
sub_url(content)
end
2008年12月9日 星期二
default,time,format
Set the default date format for your Rails application
修改 Ruby 預設的 Time 顯示格式
#加在environment.rb
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(
:default => '%Y年%m月%d日',
:date_time12 => "%m/%d/%Y %I:%M%p",
:date_time24 => "%m/%d/%Y %H:%M"
)
2008年12月2日 星期二
What's New in Edge Rails: No More Formatted Routes
No More Formatted Routes
# Old => New
formatted_article_path(article, :xml) => article_path(article, :format => :xml)
formatted_new_article_path(:json) => new_article_path(:format => :json)
# etc...
較舊的文章
首頁
訂閱:
文章 (Atom)