2012年5月27日 星期日
2012年5月17日 星期四
[ROR] rails 轉換 HTMLEntities
今天在轉換資料從 MSSQL (BIG5 編碼) to MySql (UTF8)
遇到文字內有 ♥ 等 HTMLEntities
在 MSSql 需要 encode 才能儲存
但現在 MySql 已經可以一直接存放 ♥ = ♥
在Ruby 有好用的gme 可以直接轉換
HTMLEntities
https://github.com/threedaymonk/htmlentities
範例
遇到文字內有 ♥ 等 HTMLEntities
在 MSSql 需要 encode 才能儲存
但現在 MySql 已經可以一直接存放 ♥ = ♥
在Ruby 有好用的gme 可以直接轉換
HTMLEntities
https://github.com/threedaymonk/htmlentities
範例
Decoding
require 'htmlentities'
coder = HTMLEntities.new
string = "élan"
coder.decode(string) # => "élan"
Encoding
This is slightly more complicated, due to the various options. The encode method takes a variable number of parameters, which tell it which instructions to carry out.
require 'htmlentities'
coder = HTMLEntities.new
string = "<élan>"
Escape unsafe codepoints only:
coder.encode(string) # => "<élan>"
Or:
coder.encode(string, :basic) # => "<élan>"
2012年5月14日 星期一
[MAC] 如何讓MAC顯示隱藏檔
1 啟用顯示隱藏檔
在終端機下輸入指令"defaults write com.apple.finder AppleShowAllFiles -bool true",然後強制重新啟動Finder(左上角小蘋果圖示-->強制結束-->選擇"Finder")
2 關閉顯示隱藏檔
在終端機下輸入指令"defaults write com.apple.finder AppleShowAllFiles -bool false",然後強制重新啟動Finder即可(左上角小蘋果圖示-->強制結束-->選擇"Finder")
2012年5月7日 星期一
[ROR] 使用 validates_acceptance_of
validates_acceptance_of
http://guides.rubyonrails.org/v2.3.8/activerecord_validations_callbacks.html#validates-acceptance-of
attr_accessible :terms
validates_acceptance_of :terms
訂閱:
文章 (Atom)