Very brief

@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.

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 24 February 2010 14:25, ben wiseley [email protected] wrote:

‘#{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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs