# To\_date method problems

**URL:** <https://www.ruby-forum.com/t/to-date-method-problems/153862>\
**Category:** Rails\
**Created:** [November 21, 2008, 10:58pm UTC](https://www.ruby-forum.com/t/to-date-method-problems/153862 "2008-11-21T22:58:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cam295](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@cam295](https://www.ruby-forum.com/u/cam295)\
**Post date:** [November 21, 2008, 10:58pm UTC](https://www.ruby-forum.com/t/to-date-method-problems/153862/1 "2008-11-21T22:58:24Z")

</div>

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:in`find\_recent\_invoices’  
/app/controllers/admin/communicate\_controller.rb:96:in  
`send_invoices' /app/controllers/admin/communicate_controller.rb:95:in`each’  
/app/controllers/admin/communicate\_controller.rb:95:in  
`send_invoices' /vendor/rails/actionpack/lib/action_controller/base.rb:849:in`send’  
/vendor/rails/actionpack/lib/action\_controller/base.rb:849:in  
`perform_action_without_filters' /vendor/rails/actionpack/lib/action_controller/filters.rb:332:in`perform\_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:in`measure’  
/vendor/rails/actionpack/lib/action\_controller/benchmarking.rb:69:in  
`perform_action_without_rescue' /vendor/rails/actionpack/lib/action_controller/rescue.rb:82:in`perform\_action’  
/vendor/rails/actionpack/lib/action\_controller/base.rb:369:in `send' /vendor/rails/actionpack/lib/action_controller/base.rb:369:in`process\_without\_session\_management\_support’  
/vendor/rails/actionpack/lib/action\_controller/session\_management.rb:116:in  
`process' /vendor/rails/railties/lib/dispatcher.rb:38:in`dispatch’  
/lib/fcgi\_handler.rb:136:in `process_request' /lib/fcgi_handler.rb:62:in`process!’  
/usr/lib/ruby/1.8/fcgi.rb:612:in `each_cgi' /usr/lib/ruby/1.8/fcgi.rb:609:in`each’  
/usr/lib/ruby/1.8/fcgi.rb:609:in `each_cgi' /lib/fcgi_handler.rb:53:in`process!’  
/lib/fcgi\_handler.rb:20:in `process!’  
dispatch.fcgi:24

---

<div class="post-metadata">

**Author:** ![cam295](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@cam295](https://www.ruby-forum.com/u/cam295)\
**Post date:** [November 21, 2008, 11:33pm UTC](https://www.ruby-forum.com/t/to-date-method-problems/153862/2 "2008-11-21T23:33:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cam295](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/73ab20/32.png) [@cam295](https://www.ruby-forum.com/u/cam295)\
**Post date:** [November 22, 2008, 6:13am UTC](https://www.ruby-forum.com/t/to-date-method-problems/153862/3 "2008-11-22T06:13:58Z")

</div>

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

> 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
