Sorting problem

hi,

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] =""
@panle_sel_id=params[:pan]
panel = Panel_question.find(:all,
:conditions=>[“panel_id=?”,@panle_sel_id])

#render :text => panel1.panel_id.to_s

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

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

end

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
array.sort -> an_array
array.sort {| a,b | block } -> an_array

 Returns a new array created by sorting _self_. Comparisons for

the
sort will be done using the +<=>+ operator or using an optional
code block. The block implements a comparison between a and
b,
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.

-Michael
http://javathehutt.blogspot.com