On 24 February 2010 14:25, ben wiseley <[email protected]> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to