Rails三兩事 A website introduce you ruby&rails and technology news.

25Nov/090

Productive Ruby on Rails

這陣子一直忙於專案.
之前的專案沒有使用Restful,於是寫起來有點辛苦,也不好整理.
這個專案一開始便使用Restful,配合Scaffold寫起來真的很快....
雖然,這是眾所皆知的東西了,但還是想紀錄一下.. :$

這是寫在Facebook上的文章,懶得重翻,將就一下囉.
英文不好請見諒. :p

I know why everybody say Ruby on Rails is productive now.
As most of parts, Ruby on Rails is there for you.
The only thing you need to do is just type some command and change some works.
For example. "Scaffold" is one of great tool that generate ready to go model for you.
In the one going project ,I scaffolded 4 times for all CRUD works.
Each scaffold for one set of CRUD, and it's ready with Restful style.
Only thing you need to do is build views and setting up some routes, some relationship between databases, and do a little bit work for your controller.

If you don't know what is Restful, and tried to understand how does scaffold works, it might drive you crazy.
Official docs guide you in pretty clear way : This
As others like iHower's PPT : This
And this : This

They all provide lots of information.

How easy if you go with Restful?
Sometimes,we want to create some relationship in this way : " find A user's POST "
In old way, you might create another action called "search post", and have lots of conditions in.
Maybe "find POST by user name", "find POST by comment".... as you can image, that will be lots of work to do.

In Restful way. you only need to set up relationship in routes like :

map.resources :users, :has_many=>{:posts,:comments}

then go into your each controller action "index" and add something like :

@post=find(:all,:conditions=>["user_id=?",params[:user_id]]) if params[:user_id]!=nil

then, when you type address like " users/1/posts/ " , it will show all posts by user_id 1 for u.
Cool, isn't it?

If you have further question, welcome discuss with me.

24Nov/090

Shift to Xubuntu

Ubuntu有好多版本.
你知道差別嗎,你最喜歡哪個?

我最喜歡Xubuntu. 因為他快. :)

Ubuntu有點慢,即使桌面特效全關. 尤其升9.10後(有人知道為什麼嗎?)
Xubuntu很快,開機動畫我也喜歡. 很穩定.
Kubuntu自從9.04?之後,桌面改得亂七八糟,一堆Widget. 就不想用了....

你呢?

小抱怨,Linux上的FF怎麼那麼爛... 很慢.. 尤其開Facebook.. 整個就是 慢速播放*8倍...
又懶得花時間去搞..

24Nov/090

Really need to edit the theme of this blog….

嗯. 很久沒有寫.. 真的得花時間整理整理這個blog.
除了改一改Theme,Css. 還得多補充一點內容.

等下個月. 開發到一段落.比較不那麼忙時..

話說,誰說寫網頁很簡單. 一堆雞毛的事....
當然也一堆Trick & Security Issue.
除非只是做個公司形象網站那種的,另當別論.

不過..
要這樣講的話,寫應用程式很簡單.
只是拉一拉方塊,寫一寫對應,一個簡單的計算機10分鐘就出來了.

要這樣講的話,做業務很簡單.
只是話講一講,喝個茶,出一張嘴.

要這樣講的話,做行銷也很簡單.
只是SEO弄一弄,企劃打一打,圖弄一弄
搖搖叫一叫(是叫來演出廣告...:p)

要這樣講的話,做美工也很簡單.
只是線拉一拉,圖貼上剪下,淡化一下,調一下色
最多拍個照片,修一修就好了

但是,從來都不是那麼簡單.
任何事,都不要小看. :)

Filed under: Uncategorized No Comments
24Nov/090

Q101 on Ubuntu

3G網卡要在Linux驅動是很麻煩的一件事.
9.10前的版本更是麻煩,得設定,還得寫script.
9.10後就有更快地作法了.

按Alt+F2,輸入gksudo gedit /etc/udev/rules.d/30-q101.rules後,按執行
把以下內容貼進去

#
# first, q101 will be detected as usb_storage of 0408:1000
# you have to force it suspend to change running mode from
# storage to 3.5g card

SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ACTION=="add", ATTRS{idVendor}=="0408", ATTRS{idProduct}=="1000", RUN+="/bin/sh -c 'cd /sys$env{DEVPATH};until test -f power/level;do cd ..;done;if [ -f power/level ];then echo suspend > power/level;fi'"
存檔後重開機

插入網卡過幾秒應該就可以看到,選TW Mobile.
Edit Connection:

Number: *99#
Username: username
password: passwd
APN: Internet

(重開)即可.

5Nov/090

關於HostingRails Domain

最近都在弄Domain的東西.
有鑑於上次有忘記怎麼弄,還去查官方說明,所以紀錄一下.

若多個指向一個(原本預設之根目錄),則去ParkDomain新增即可.
若指向非預設資料夾,則去AddonDomain新增.
:)