2010-10-17 133 views
0

我對你有幾個問題Rails 3大師在那裏。你如何完成以下任務?Rails 3 ActiveRecord問題

以下僞代碼當前無效。謝謝大家。

@items = (@itemsA + @itemsB).order("name ASC") 

@item = Item.where("type = ?" and "condition = ?", "book", "new") 

@commenteditems = Item.find_all_by_type_and_condition("book", "new").include("notes").select("item[name]", "notes[note]") 

@selecteditems = @items.where("select = ?", true) 

回答

1

我相信你要找的是scopes

+0

上述四個博士學位都需要範圍嗎?我會認爲數字2至少可以用基本查詢來完成。 – sscirrus 2010-10-17 05:26:43

+0

第二個可能會工作得很好。範圍的事情是,它使您能夠將邏輯從控制器推送到模型。以這種方式,你的控制器只是獲取數據而不知道如何獲取數據。 – MunkiPhD 2010-10-18 12:02:58