Hello, i am very new to RoR and last 2 weeks i ve been reading a lot about them.. I have manage to create a quick application, but i am having problems figuring out how to sort the fields.. [code] def list @running = Boards.find_all("running = 1") @waiting = Boards.find_all("waiting = 1") @on_hold = Boards.find_all("running = 0", "waiting = 0") end [/code] Thats what i have as the list def and it works but it order is as first in... I tried the following: [code] def list @running = Boards.find(:all, :conditions => "running = 1", :order => priority ASC, quantity DESC'') @waiting = Boards.find(:all, :conditions => "waiting = 1", :order => priority ASC, quantity DESC'' @on_hold = Boards.(:all, :conditions => "running = 0, waiting = 0", :order => priority ASC, quantity DESC'' end [/code] And it gives me errors... I need to sort them with ASC priotity and DESC quantity (priority and quantity are columns on my table) Any ideas...? Thanks -- 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 -~----------~----~----~----~------~----~------~--~---
Ro Vent wrote:> Hello, i am very new to RoR and last 2 weeks i ve been reading a lot > about them.. > > I have manage to create a quick application, but i am having problems > figuring out how to sort the fields.. > > [code] > def list > @running = Boards.find_all("running = 1") > @waiting = Boards.find_all("waiting = 1") > @on_hold = Boards.find_all("running = 0", "waiting = 0") > end > [/code] > > Thats what i have as the list def and it works but it order is as first > in... I tried the following: > > [code] > def list > @running = Boards.find(:all, :conditions => "running = 1", :order => > priority ASC, quantity DESC'') > @waiting = Boards.find(:all, :conditions => "waiting = 1", :order => > priority ASC, quantity DESC'' > @on_hold = Boards.(:all, :conditions => "running = 0, waiting = 0", > :order => priority ASC, quantity DESC'' > end > [/code] > > And it gives me errors... I need to sort them with ASC priotity and DESC > quantity (priority and quantity are columns on my table) > > Any ideas...? > > ThanksPlace your :order in quotes: @running = Boards.find(:all, :conditions => "running = 1", :order => "priority ASC, quantity DESC"'') Also, you may want to tail the development log to see the SQL being generated. -- 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 -~----------~----~----~----~------~----~------~--~---
Ro Vent wrote:> > Hello, i am very new to RoR and last 2 weeks i ve been reading a lot > about them.. > > I have manage to create a quick application, but i am having problems > figuring out how to sort the fields.. > > [code] > def list > @running = Boards.find_all("running = 1") > @waiting = Boards.find_all("waiting = 1") > @on_hold = Boards.find_all("running = 0", "waiting = 0") > end > [/code] > > Thats what i have as the list def and it works but it order is as first > in... I tried the following: > > [code] > def list > @running = Boards.find(:all, :conditions => "running = 1", :order => > priority ASC, quantity DESC'') > @waiting = Boards.find(:all, :conditions => "waiting = 1", :order => > priority ASC, quantity DESC'' > @on_hold = Boards.(:all, :conditions => "running = 0, waiting = 0", > :order => priority ASC, quantity DESC'' > end > [/code] > > And it gives me errors... I need to sort them with ASC priotity and DESC > quantity (priority and quantity are columns on my table) > > Any ideas...? > > Thanks >It looks like you are missing quotes around your :order params. Matthew Margolis blog.mattmargolis.net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
what''s the error? it could be that Boards.find is including other associations so you might need to write something like @running = Boards.find(:all, :conditions => "running = 1", :order => " boards.priority ASC, quantity DESC") though looking at your pasted code, you have a single quote before the closing paren (which is missing on 2 of the lines) that was never opened...that could also be your issue. ed On 1/15/07, Ro Vent <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hello, i am very new to RoR and last 2 weeks i ve been reading a lot > about them.. > > I have manage to create a quick application, but i am having problems > figuring out how to sort the fields.. > > [code] > def list > @running = Boards.find_all("running = 1") > @waiting = Boards.find_all("waiting = 1") > @on_hold = Boards.find_all("running = 0", "waiting = 0") > end > [/code] > > Thats what i have as the list def and it works but it order is as first > in... I tried the following: > > [code] > def list > @running = Boards.find(:all, :conditions => "running = 1", :order => > priority ASC, quantity DESC'') > @waiting = Boards.find(:all, :conditions => "waiting = 1", :order => > priority ASC, quantity DESC'' > @on_hold = Boards.(:all, :conditions => "running = 0, waiting = 0", > :order => priority ASC, quantity DESC'' > end > [/code] > > And it gives me errors... I need to sort them with ASC priotity and DESC > quantity (priority and quantity are columns on my table) > > Any ideas...? > > Thanks > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Ed Hickey Developer Litmus Media 816-533-0409 ehickey-A4HEbNdjHgMmlAP/+Wk3EA@public.gmane.org A Member of Think Partnership, Inc www.ThinkPartnership.com Amex ticker symbol: THK --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks i overlooked at that.... After i addded the quotes it worked, however that only evaluates one expresion: @on_hold = Boards.find(:all, :conditions => "running = 0, waiting = 0", :order => "priority ASC, quantity DESC") That means that it only takes one condition after the :conditions =>.... Is there a simple way of taking 2 conditions...? Also i have date fields and i was wondering how can i only display the month and day....? At this moment it displays 2007-01-19 and i want it to display 01-19.... Thanks.. -- 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 -~----------~----~----~----~------~----~------~--~---
Ro Vent wrote:> After i addded the quotes it worked, however that only evaluates one > expresion: > > @on_hold = Boards.find(:all, :conditions => "running = 0, waiting = 0", > :order => "priority ASC, quantity DESC") > > That means that it only takes one condition after the :conditions =>.... > Is there a simple way of taking 2 conditions...?The :conditions option is simply an SQL fragment that gets inserted into the SQL WHERE clause, so you can indeed only specify one "condition". However, that condition can be anything that is valid in a WHERE clause ... in your case, you would want it to be: @on_hold = Boards.find(:all, :conditions => "running = 0 AND waiting = 0", :order=> "priority ASC, quantity DESC") As a side note, specifying the :conditions option as a single string is fine if you are completely specifying the conditions in your code. However, if any part of it is coming from user input, you will need to use the array form of the :conditions option to prevent against SQL injection. For example: @employees = Employee.find(:all, :conditions => ["last_name = ?", params[:last_name]]) See the documentation for the find method for details: http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000860 -- 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 -~----------~----~----~----~------~----~------~--~---