根据您的查询,请在您的控制器写这样
@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