> @jobs = Job.find(:all, :conditions => "#{Date.parse(str="#{closing_date}")} >= #{Date.today.strftime("%d/%m/%Y")}")In the above instance, ''closing_date'' is a string. I want to ensure that only instances of Job where the closing date is greater than or equal to today''s date are pulled into an array. Please can someone rectify this code; I''m not sure where it''s going wrong. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You should probably convert closing_date to a datetime datatype in the DB if possible: script/generate migration change_closing_date ... in the migration ... change_column :jobs, :closing_date, :datetime Otherwise you might try: # add '' and consistent formating @jobs = Job.find(:all, :conditions => "''#{Date.parse(str="#{closing_date}").to_s(:db)}'' >''#{Date.today.to_s(:db)}''") On Wed, Feb 24, 2010 at 5:48 AM, Pale Horse <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > @jobs = Job.find(:all, :conditions => > "#{Date.parse(str="#{closing_date}")} >> #{Date.today.strftime("%d/%m/%Y")}") > > In the above instance, ''closing_date'' is a string. I want to ensure that > only instances of Job where the closing date is greater than or equal to > today''s date are pulled into an array. > > Please can someone rectify this code; I''m not sure where it''s going > wrong. > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 24 February 2010 14:25, ben wiseley <wiseleyb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You should probably convert closing_date to a datetime datatype in the DB if > possible: > script/generate migration change_closing_date > ... in the migration ... > change_column :jobs, :closing_date, :datetime > > Otherwise you might try: > # add '' and consistent formating > @jobs = Job.find(:all, :conditions => > "''#{Date.parse(str="#{closing_date}").to_s(:db)}'' >> ''#{Date.today.to_s(:db)}''") >The biggest problem with this finder is that it''s not querying any table fields. You seem to be just saying "where ''1 jan 2010'' >= ''1 jan 2010''" (substitute appropriate values for closing date and current date). So essentially you''re writing a query that says "if closing day is today or greater, give me every record in the table, otherwise, don''t give me any"> @jobs = Job.find(:all, :conditions => "jobs.closing_date >= ''#{Date.today.to_s(:db)}''"this would at least be a starting point, as you''d then be interrogating the closing_date field. Go and have a play with different queries in your SQL console. When you know how the query should look to get the result you want, you should be able to translate the conditions from that into a Rails finder. Test it in IRB to get to a solution working. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.