Sorting problem


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

panel.each do |rows|
demo = Demographic_category.find(:all, :conditions=> [“id=?”,p_id]);
@text+="" + +
session[:mov_id] += “,” + p_id.to_s

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


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"]

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.