Ruby on Rails

4
Apr

使用Active Record時可以使用 Model.find(:first)來取出第一筆資料,或是Model.find(:all)來取出全部的資料,那如果想要取出最近的一筆資料該怎麼做呢?其實只需要加個排序的條件即可。

範例:

@event = Event.find(:first, : order => "created_at DESC")

Updated: 補充一下,其實如果是@event = Event.find(:all),那麼@event.last便是最後一筆資料了。

Category : Ruby on Rails | Blog
23
Mar

昨天在網路上抓到的一張Ruby on Rails的架構圖,點圖可放大。

P.S.若有侵權請來信告知deduce_@_gmail.com, thanks!

Category : Ruby on Rails | Blog
18
Mar

我連Agile Web Development with Rails都還沒看完,就迫不及待拿出Rails Recipes開始看看裡面提供了些什麼有趣的玩意兒。Rails Recipes這本書比較適合已經對於Ruby on Rails有點瞭解,甚至是已經開始製作、經營網站的User,裡面提供了一些很實用的技巧,共70個Recipes分成以下幾篇:

  • User Interface Recipes
  • Database Recipes
  • Controller Recipes
  • Testing Recipes
  • Big-Picture Recipes
  • Email Recipes

我覺得這本書跟Agile Web Development with Rails都很有收藏價值,Rails Recipe在每一章的開頭會先敘述一段網站開發者可能遭遇的「Problem」(或是一段簡單的場景敘述),隨後列出需要準備的「Ingredients」,並且提出對應的「Solution」,內容我認為是簡短有力,沒事拿來當閒書翻閱一下或是放在旁邊當工具書參考用都很有幫助。

註:另一本「Advanced Rails Recipes」預計在August 2007出版,真是令人期待!
http://www.pragmaticprogrammer.com/titles/fr_mrr/index.html

Category : Books | Ruby on Rails | Blog
17
Mar

http://rubycorner.net/articles/22-successful-ruby-on-rails-web-applications/

這篇文章介紹了22個成功的Ruby on Rails個案,稍微做個簡單的中文翻譯替螢幕前的訪客省點時間好了:)

(另外在http://happycodr.com/biglist有更多的網站介紹,共有388個!)

第一部份主要是37signals他們公司所經營的網站,

  1. Basecamp
    http://www.basecamphq.com
    專案管理網站
  2. Campfire
    http://www.campfirenow.com
    即時群組聊天網站
  3. Backpack
    http://www.backpackit.com
    資訊彙整與行事曆網站
  4. Tadalist
    http://www.tadalist.com
    簡單好用的Todo List(要做的事)
  5. Writeboard
    http://www.writeboard.com
    線上共同編輯文件

第二部份則是在RubyonRails.org有介紹的網站,

  1. 43things.com
    http://www.43things.com
    這個網站也算是Web 2.0與Ruby on Rails的經典網站,人們可以上去分享自己想做的事情,藉此來找到跟自己有著相同目標的朋友們。
  2. odeo.com
    http://odeo.com
    音樂分享網站
  3. shopify.com
    http://shopify.com
    提供使用者快速建立屬於自己的電子商務網站
  4. fluxion
    http://www.fluxiom.com
    管理、組織並分想你的數位資產
  5. strongspace.com
    http://www.strongspace.com
    File hosting檔案分享網站
  6. Typo
    http://www.typosphere.org
    Blogging engine,這在Ruby on Rails也算是很紅的一套blog系統

第三部份應該是筆者自行發現的網站,還滿不錯的~看到好多以前沒逛過的站

  1. ajaxed.com
    http://www.ajaxed.com
    不需要寫程式即可輕輕鬆鬆在你現有的網站上加上Ajax的效果
  2. atopsites.com
    http://atopsites.com
    仿Alaxa.com的網站
  3. asoboo.com
    http://asoboo.com
    針對Creative people所設立的社群網站(筆者特別強調該網站是佈署在Win2003)
  4. thebeststuffintheworld
    http://www.thebeststuffintheworld.com
    有趣的web 2.0應用
  5. dealplumber.com
    http://www.dealplumber.com
    另一個有趣的社群網站
  6. digital-tunes.net
    http://www.digital-tunes.net
    專做音樂的電子商務網站
  7. flagr.com
    http://www.flagr.com
    看起來應該是跟Google map有關的Mashup
  8. godefy.com
    http://www.godefy.com
    有關網路行銷公司或產品的比較
  9. lovexpress.fr
    http://www.lovexpress.fr
    法國的交友網站
  10. podomatic.com
    http://podomatic.com
    專門分享podcasts的網站
  11. pixrat.com
    http://www.pixrat.com
    Social picture bookmars,人家del.icio.us做的是書籤,pixrat做的是「圖籤」,其實前陣子出現的diggirl概念就類似Pixrat,都是要收藏美女並且用類似「digg」的方式來推選出本日熱門,不過Pixrat的精神比較接近書籤,比較著重在收藏、分享,而diggirl則是著重在本日最熱門,比較接近digg的概念。(但diggirl同時又搭配幹圖王可以收藏,還滿威的!)
Category : Ruby on Rails | Web2.0 Website | Blog
14
Mar

http://www.antoniocangiano.com/articles/2007/02/10/top-10-ruby-on-rails-performance-tips

作者提出十個針對Ruby on Rails Performance的小技巧,有興趣的可以到該網頁參考。

  1. Optimize your Ruby code.
  2. Caching is good.
  3. Use your database to the full extent of the law.
  4. Finders are great but be careful.
  5. Group operations in a transaction.
  6. Control your controllers.
  7. Use HTML for you views.
  8. Logging.
  9. Patch the GC.(Garbage Collection)
  10. A final not, be "performance aware" and work on your code with these principle in mind.
Category : Ruby on Rails | Blog