雖然InstantRails 1.7搭配的是MySQL 5,但還是習慣在專案的 config/database.yml中設定unicode,這樣可以避免存進去拿出來的資料變成亂碼,或者使用phpMyadmin看的時候看不到內容。

設定方式類似底下:

  adapter: mysql
  database: houcan_test
  username: root
  password:
  host: localhost
  encoding: utf8

 值得注意的是,之前寫utf-8可以過,在1.7這個版次寫 utf-8卻會說

C:\projects\xxx>rake db:migrate
(in C:/projects/xxx)
Character set ‘utf-8′ is not a compiled character set and is not specified in th
e ‘C:\mysql\\share\charsets\Index.xml’ file
rake aborted!
Can’t initialize character set utf-8 (path: C:\mysql\\share\charsets\)

(See full trace by running task with –trace)

那就寫utf8囉。

Leave a Reply