根據您的查詢,請在您的控制器寫這樣
@stories = Story.where("stories.content IS NOT NULL") #Records those has a content
@stories = Story.where("stories.title LIKE%a_certain_word_or_phrase%") # Records that contains a certain word or phrase
如果你想拿起唯一一個從DATABSE可以用戶。首先。去年例如recoed
@sotory = Story.where("stories.content IS NOT NULL").first #first item which has content
@sotory = Story.where("stories.content IS NOT NULL").first #last item which has content
你也可以通過ID找到像
@story = Story.find(1) # finds the record with id = 1
等等......
我覺得你需要一個好的tutorial.As你是一個新手,請結帳Ruby on Rails Guides: Active Record Query Interface
您是否創建了任何控制器?你不能像在PHP中那樣在頁面上執行SQL(不應該)。 – woz 2013-04-25 15:10:24
woz是正確的。您的查詢屬於您的控制器,這些控制器會公開顯示在視圖中的數據。 – 2013-04-25 15:21:29