Forum: Ruby on Rails sorting problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
46911700017303070d64f73b69bb04a8?d=identicon&s=25 Guest (Guest)
on 2007-02-22 06:16

  i want to list out sorted data in list boxes. but in i don't how to
use sorting in ROR. so can anyone tell me. actually i want to list out
the demographic categories.

my coding is,

def sel_panel
#session[:mov_id] += "," + @demo_id
session[:mov_id] =""
  panel = Panel_question.find(:all,

  #render :text => panel1.panel_id.to_s

 @text="<select id='toBox' multiple size='8'>"
   panel.each do |rows|
    demo = Demographic_category.find(:all, :conditions=> ["id=?",p_id]);
    @text+="<option  value='" + p_id.to_s + "'>" + +
    session[:mov_id] += "," +  p_id.to_s

  render :text => @text
   #@test=Panel_question.find(params[:demographic_category_id ])

403f733cb3c9e8d45a86965399a7887f?d=identicon&s=25 Doug McBride (Guest)
on 2007-02-22 06:32
(Received via mailing list)
This is straight from the Ruby documentation.  Without knowing
anything about the type of objects you're trying to sort, I can't be
of any more help.

     array.sort                   -> an_array
     array.sort {| a,b | block }  -> an_array
     Returns a new array created by sorting _self_. Comparisons for
     sort will be done using the +<=>+ operator or using an optional
     code block. The block implements a comparison between _a_ and
     returning -1, 0, or +1. See also +Enumerable#sort_by+.

        a = [ "d", "a", "e", "c", "b" ]
        a.sort                    #=> ["a", "b", "c", "d", "e"]
        a.sort {|x,y| y <=> x }   #=> ["e", "d", "c", "b", "a"]
361ba1bcc1d2c5a8885dd093dbb96bb6?d=identicon&s=25 Michael Kovacs (Guest)
on 2007-02-22 07:14
(Received via mailing list)
checkout the :order parameter to your finder call. Don't sort in ruby
unless you really have to. Let the database do its job and sort for
you. It's eagerly awaiting that opportunity to serve you.

This topic is locked and can not be replied to.