• Set your browser encoding to UTF-8.

Weblog

Monday, 19 January 2009

  • 裝Attachment_fu

    裝attachment_fu畀Rails用好易。

    首先裝咗ImageScience先。
    裝法:
    $ sudo gem install image_science

    跟住作去Rails嗰個App嘅目錄,裝attachment_fu
    $ script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/

    之後,起個class table畀啲file
    class CreateUploadFile < ActiveRecord::Migration
    def self.up
    create_table :upload_files do |t|
     # 所有都用
    t.string :content_type
    t.string :filename
    t.integer :size
    # image 用
    t.integer :width
    t.integer :height
    # thumbnail 用
    t.string :thumbnail
    t.integer :parent_id
    # 如果揀用database儲file
    t.references :db_file
    end
    end
    def self.down
    drop_table :upload_files
    end
    end

    #如果用database儲
    def CreateDbFiles < ActiveRecord::Migration
    def self.up
    create_table :db_files do
    t.binary :data
    end
    end
    def self.down
    drop_table :db_files
    end
    end
    係咁樣,搞掂。

    個class UploadFile入便,
    加has attachment同佢一堆option搞掂。

    跟住係整view或controller控制。


Thursday, 15 January 2009

  • Rails format

    Rails要回返啲嘢畀client之前,會check返有client有send啲乜Accept過來。

    畀個例
    首先要/objects/1.html
    Client交呢個Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Rails就會搵html個項
    respond_to do |format|
      format.html ...
      format.xml ...
      format.jpg ...
      format.all ...
    end

    對個對法係來自個type有無做Mime.register
    Mime.register其中一行,有mime type係text/html,extension係html,symbol係:html
    咁對html, 搵有:html,咁就夾format.html

    咁Rails交出之時,就會對下Accept有無:html嘅mime type,對到有text/html,咁就send出去。

    如果client無話可以Accept,就會話406 Not Accepted。

    之不過Rails唔夠聰明,就算*都要指明,唔係佢唔識handle㗎。不過佢留有*/*來map去:all,咁format.all就會handle得到。


Thursday, 08 January 2009

  • 地名

    想砌下地名對譯,個表會不時更新。

    基隆
    Keelung
    1928-04-28


    龍門




    日本
    Japan



    門司
    毛之
    Moji


    上海
    Shanghai



    省城
    Canton



    西貢
    Saigon



    星加波
    星架波

    石叻
    Singapore


    Selat



    廣州灣




    小呂宋




    海口
    Hoihow



    濱角




    張家口
    Kalgan



    廣東
    Kwangtung



    河內
    Honoi



    涵館
    Hakodate



    牛莊
    牛庄
    Newchwang



    大連




    鎮江
    Chinkiang



    盧州
    Lu how?



    神戶
    Kobe



    大阪
    Osaka



    橫濱
    Yokohama



    汕頭
    Swatow



    青島




    三水




    梧州




    毛厘士
    Maurice

    毛里裘斯
    Mauritis
    布旺
    Bourbon

    留尼旺
    Réunion
    南斐洲
    South Africa



    八打威
    Batavia



    三孖冷
    Semarang



    泗水
    Soerabaja


    Surabaja
    孟加失
    Mangkasar


    Makassar/Macassar
    舊金山
    California
    San Francisco



    羅省
    Los Angelos



    美國
    花旗
    United States of America



    中南美洲




    域多利
    Victoria (Canada)



    溫高華
    咸水埠
    Vancouver



    加拿大
    Canada



    檀香山
    檀山
    Honolulu



    墨西哥
    Mexico



    中美洲
    Central America



    舍路
    Seattle



    北海
    Pakhoi



    巴拿馬
    巴剌孖
    吧拿堡
    Panama



    巴波啞
    Balboa



    告郎
    Colón



    鳥約
    New York



    廈門
    Amoy


    Xiamen
    安南
    Annam



    海防
    Haiphong



    打狗
    Takao

    高雄
    Kao Hsiung
    赤坎




    希路
    Hilo



    文成李祐
    Manzanillo



    秘魯
    Peru
    Perú



    智利
    Chile



    瑞典
    Sweden



    哥林堡
    哥霖步
    Colombo



    庇能
    Penang

    檳城

    仰光




    架厘吉打
    架剌吉打
    Calcutta



    大連




    威海衞
    Weihaiwei



    烟台
    煙台




    天津




    河口




    英京
    倫敦
    London



    山打根
    Sandakan



    笠包
    Rabaul



    雪梨
    Sydney


    美利伴
    美利畔
    Melbourne


    阿地利埠
    Adelaide



    福州




    暹邏
    Siam



    孟米
    Bombay



    馬些
    Marseille



    夏華
    Havre



    律打担
    Rotterdam



    咸北
    Hamburg



    他士爹島
    Thursday Island



    湯士威路
    Townsville



    庇利士彬
    Brisbane



    新金山
    Australia



    波士頓
    Boston



    打畸
    Durban



    刦當
    Cape Town



    南美洲
    South America



    意大利
    Italy



    歐洲
    Europe



    錫蘭
    Ceylon



    斐洲
    Africa



    埃及
    Egypt



    渣華
    Java



    台灣




    美洲
    America



    印度
    India



    雅典
    Aden? Athens?



    紐西蘭
    New Zealand



    肇慶





































































Wednesday, 07 January 2009

  • Rails migration 整數改咗rule

    家下Rails class Migration::Base之下

    以前咁寫
    t.integer :amount
    預設係MySQL int(11),係幾個數字。
    家下Rails改咗用byte計,咁:limit個數字就唔同咗意思。
    1 byte等於MySQL tinyint
    2 byte係smallint
    3 byte係mediumint
    4 byte係int(11)
    5..8 byte係bigint

    咁為咗同舊時一樣nil同11作同等同家下4,即係default都係4
    大過8, rails migration會鬧你。

  • Debian用exim4寄信

    Debian預設係用exim4收信寄信。

    如果唔使收信,而自己部機做埋SMTP server,直接寄信出去。

    可以行
    $ dpkg-reconfigure exim4-config
    Split configuration into small files? Yes 同 No都得。
    揀internet site; mail is sent and received directly using SMTP。
    system mail name做localhost.localnet。
    ip收信。127.0.0.1。
    destination吉咗。
    relay mail兩次都吉咗。
    Keep number of DNS-queries minimal做No。
    揀mbox format in /var/mail/。

    搞掂。

ruby_omnibus

  • Visit ruby_omnibus's Xanga Site
    • Name: ruby_omnibus
    • Gender: Male
    • Member Since: 1/22/2008
    • True

About Me

  • I'm working on Ruby on Rails. I am Cantonese speaker and thus my blog is mainly in Cantonese. I am comprehensible in English, Cantonese, modern Chinese and classic Chinese. Also, I learnt a little bit Japanese especially with more Kanji. Please feel free to write to me.¶ Below is in Cantonese.¶ 歡迎大家留言、寫下回應、同埋同我傾偈。

Weblog Archives

Don't worry - your calendar is here… to see it in action just click "Save" above and refresh the page.

Blogrings

[no blogrings]

Pulse

ruby_omnibus has no pulse!...

Recommended

[no recommendations]