根据您的查询,在您的控制器中写如下
@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
如果您只想从数据库中获取一个 recoed,您可以使用 .first .last 例如
@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
等等 ......
我认为您需要一个很好的教程。由于您是新手,请查看Ruby on Rails 指南:Active Record 查询接口