Groups
Groups
Sign in
Groups
Groups
Ruby on Rails Taiwan
Conversations
About
Send feedback
Help
ROR於Windows下的中文檔案及目錄解法(以Big5為例)
13 views
Skip to first unread message
JellyCatz果凍喵
unread,
May 17, 2008, 10:39:21 PM
5/17/08
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails Taiwan
嗯...因為目前自己身處的環境的關係...Client端100%使用IE,Server端100%使用Windows Server
2003...一整個超級傻眼|||
Server用Windows最大的問題莫過於Big5的"許蓋功",ROR處理Big5時一程度還是會水土不服的掛點,嗯...so~ 解法大概就是
ROR及Apache及DB全部使用UTF8,操作檔案及目錄時才把要處理的path轉為BIG5後再處理,而ROR把處理後的靜態的檔案及目錄都
pass給Apache去處理,Client取檔案時是透過Apache而非ROR,到目前測試這樣的模式完美得很
[Clinet] <==> Apache <==> ROR <==> DB
^==(Storage)==^
Storage.path.convert(UTF8 => BIG5).save
存檔:Client send file => ROR path.convert(UTF8 => BIG5) => ROR save
取檔:Client request => Apache(proxy pass /datas/....) => get file =>
send
而這種解法其實只需要單向的把UTF8轉成BIG5,因為IE(6.0+)的URL全部都是UTF8傳送,Apache會自動轉換成BIG5並抓到正確
的路徑及檔案,不用把request的URI再轉換一次(BIG5 => UTF8)
轉換時只需要
require 'iconv'
after_string = Iconv.new('UTF-8', 'BIG5' ).iconv(begin_string) # 正轉
BIG5 => UTF8
after_string = Iconv.new('BIG5','UTF-8' ).iconv(begin_string) # 反傳
UTF8 => BIG5
至於URI可能為Big5的Firefox會不會有問題......Orz"未測,目前這種方式除了一些Windows內命名時禁用的特殊符號及跳脫字
元不能使用外,其餘像是"許蓋功"之類的完全沒問題,而存檔時也要記得把每段路徑的左右空白去除,就應該可以得到很好的結果......嗯~ 有人有測
過or對主題有更好的看法,請提出來的:)
Reply all
Reply to author
Forward
0 new messages