views:

21

answers:

1

I have a few queries for you Rails 3 gurus out there. How can you accomplish the following?

The following pseudocode is currently invalid. Thanks all.

@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  A: 

I believe what you're looking for is scopes.

MunkiPhD
Are scopes necessary for all of the above four PhD? I would have thought number 2 at least can be done with a basic query.
sscirrus
The second one would probably work fine how it is. The thing with scopes is that it enables you to push the logic from the controller to the model. In that manner, your controller just gets the data and not figuring out HOW to get the data.
MunkiPhD