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="<select id=''toBox'' multiple size=''8''>" panel.each do |rows| p_id=rows.demographic_category_id demo = Demographic_category.find(:all, :conditions=> ["id=?",p_id]); demo1=demo[0] @text+="<option value=''" + p_id.to_s + "''>" + demo1.name.to_s + "</option>" session[:mov_id] += "," + p_id.to_s end @text+="</select>" render :text => @text #@test=Panel_question.find(params[:demographic_category_id ]) end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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"] On Feb 21, 9:16 pm, Guest <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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="<select id=''toBox'' multiple size=''8''>" > panel.each do |rows| > p_id=rows.demographic_category_id > demo = Demographic_category.find(:all, :conditions=> ["id=?",p_id]); > demo1=demo[0] > @text+="<option value=''" + p_id.to_s + "''>" + demo1.name.to_s + > "</option>" > session[:mov_id] += "," + p_id.to_s > end > > @text+="</select>" > render :text => @text > #@test=Panel_question.find(params[:demographic_category_id ]) > > end > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Feb 21, 2007, at 9:16 PM, Guest wrote:> > 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="<select id=''toBox'' multiple size=''8''>" > panel.each do |rows| > p_id=rows.demographic_category_id > demo = Demographic_category.find(:all, :conditions=> > ["id=?",p_id]); > demo1=demo[0] > @text+="<option value=''" + p_id.to_s + "''>" + demo1.name.to_s + > "</option>" > session[:mov_id] += "," + p_id.to_s > end > > @text+="</select>" > render :text => @text > #@test=Panel_question.find(params[:demographic_category_id ]) > > end > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---