To_date method problems


#1

I’m having problems, all of a sudden, with some code that’s been working
for years. Someone else wrote this code, and I’m just trying to
maintain it - I don’t have expert experience with ruby or rails. The
code grabs all invoices processed within the past week for a customer
and send an email to the appropriate person, like this:

finds the most recent invoices for this organization

def find_recent_invoices(number=6)
date = (Time.now - number.days).to_date
invoices.find(:all, :order => ‘posted_on asc’, :conditions =>
[“invoices.posted_on >= ?”, date])
end

I get this error:

NoMethodError (private method to_date' called for Sat Nov 15 13:32:51 -0800 2008:Time): /app/models/organization.rb:67:infind_recent_invoices’
/app/controllers/admin/communicate_controller.rb:96:in
send_invoices' /app/controllers/admin/communicate_controller.rb:95:ineach’
/app/controllers/admin/communicate_controller.rb:95:in
send_invoices' /vendor/rails/actionpack/lib/action_controller/base.rb:849:insend’
/vendor/rails/actionpack/lib/action_controller/base.rb:849:in
perform_action_without_filters' /vendor/rails/actionpack/lib/action_controller/filters.rb:332:inperform_action_without_benchmark’
/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:69:in
perform_action_without_rescue' /vendor/rails/actionpack/lib/action_controller/rescue.rb:82:inperform_action’
/vendor/rails/actionpack/lib/action_controller/base.rb:369:in send' /vendor/rails/actionpack/lib/action_controller/base.rb:369:inprocess_without_session_management_support’
/vendor/rails/actionpack/lib/action_controller/session_management.rb:116:in
process' /vendor/rails/railties/lib/dispatcher.rb:38:indispatch’
/lib/fcgi_handler.rb:136:in process_request' /lib/fcgi_handler.rb:62:inprocess!’
/usr/lib/ruby/1.8/fcgi.rb:612:in each_cgi' /usr/lib/ruby/1.8/fcgi.rb:609:ineach’
/usr/lib/ruby/1.8/fcgi.rb:609:in each_cgi' /lib/fcgi_handler.rb:53:inprocess!’
/lib/fcgi_handler.rb:20:in `process!’
dispatch.fcgi:24


#2

On Nov 21, 2008, at 1:58 PM, Charley M. wrote:

date = (Time.now - number.days).to_date
invoices.find(:all, :order => ‘posted_on asc’, :conditions =>
[“invoices.posted_on >= ?”, date])
end

I get this error:

NoMethodError (private method `to_date’ called for Sat Nov 15 13:32:51
-0800 2008:Time):

I don’t remember the particulars, but you’ve hit the mismatched ruby/
rails bug that came up about rails 1.2.3 I think it was. Maybe
1.2.6. Anyway, at one point some methods went private in ruby that
Rails used. Or vice versa. Anyway, the next version of rails put
them back because people were used to them. Google around for
specifics.

In any event, I suspect you’ve either just recently updated Ruby or
Rails when this problem started.

If it helps, the line giving you problems works for me with rails
2.1.0 and ruby 1.8.6 (2008-03-03 patchlevel 114).

Change the code to this and it should work for you:

def find_recent_invoices(number=6)
invoices.find(:all, :order => ‘posted_on asc’,
:conditions => [“invoices.posted_on >= ?”,
number.days.ago])
end

-philip


#3

Thanks for the help - you’re a life saver. I’ll be sure to let our
programmer know he lost me my Friday night. :wink:

Change the code to this and it should work for you:

def find_recent_invoices(number=6)
invoices.find(:all, :order => ‘posted_on asc’,
:conditions => [“invoices.posted_on >= ?”,
number.days.ago])
end

-philip