SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Quick Selection
-
Jul 14, 2009, 13:09 #1
- Join Date
- Jun 2009
- Posts
- 53
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Quick Selection
Hello,
I remember reading about how to do this at some point, but I don't actually remember how to do it. If I have an object "order" that contains {noodle type, noodle date, noodle price}, how would I iterate through all existing "orders" and place all noodle types into an array, non repeating? Something like this:
Code:@orders = Order.find(:all) @types = @Orders.each.select(:type, :no-repeat) #@types => {wheat, white, corn, wet} even if there are a bunch of wet noodles
-
Jul 15, 2009, 10:43 #2
- Join Date
- Jun 2009
- Posts
- 53
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Found the solution elsewhere:
Code:@types = Order.find(:all, :select => "distinct noodle_type").collect(&:noodle_type)
-
Jul 24, 2009, 08:30 #3
- Join Date
- Jan 2001
- Location
- Alkmaar, Netherlands
- Posts
- 710
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You might need an extra table to keep your types if you can change database structure, it will save lots of hassles in the long run.
model: NoodleType
And would be easy to
NoodleType.all.each do |noodle_type|
#....
end
-
Jul 27, 2009, 07:20 #4
- Join Date
- Jun 2009
- Posts
- 53
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Cool - thanks for that.
Bookmarks