SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Quick Selection

  1. #1
    SitePoint Enthusiast
    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
    Thank you

  2. #2
    SitePoint Enthusiast
    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)

  3. #3
    SitePoint Guru
    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

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cool - thanks for that.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •