« ANA ツアー検索 でDebian上のFirefoxが排除されるThunarで時刻が不明に »

Ruby on RailsでTime.now.to_dateで不具合

2007/06/10

  18:38:37 by , Categories: Linux, Programming

Link: http://adamklunick.com/2007/05/11/rails-error-to_date/

Check it OutというRailsでうごく家計簿ソフトがあるのだが、

NoMethodError in Admin#index

Showing app/views/account/_nav_show_small_balance.rhtml where line #1 raised:

private method `to_date' called for Sun Jun 10 16:05:34 +0900 2007:Time

Extracted source (around line #1):

1: total: <%= getTodayBalance(@account)%>

Trace of template inclusion: /app/views/account/_list.rhtml, /app/views/admin/partials/_nav.rhtml, /app/views/admin/index.rhtml

RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace

のようなエラーに遭遇。

どうやら、rails noのこのバグに遭遇しているようだ。
環境は、Debian Sid でRubyは1.8.6、Raisは1.2.3-2。チケットでは、Ruby 1.8.6で発生し、1.8.5では発生しないようす。

$ script/console
Loading development environment.
>> t = Time.now
=> Sun Jun 10 18:40:05 +0900 2007
>> t.to_date
NoMethodError: private method `to_date' called for Sun Jun 10 18:40:05 +0900 2007:Time
from (irb):2

チケットにあるのと同様、再現する。

このかたのブログでは、

So, dont make the same mistake as I did. Make sure to change the environment.rb file in the projects which you force to use a Rails version.

Hope this helps.

ということで助けになることを期待。

Ruby Forum
にあるDanielさんのコメントように
、実際1.8.6ではto_dateがprivateになっているために、Railsとconlictすることが示されている

This is really really minor but it would be nice if Time#to_date and
Time#to_datetime (from date.rb) were made public. I don't know why they
are private (doesn't seem very useful) but that causes a conflict with
Rails' similarly-named helper methods.

Railsのほうで、to_dateを使わないで実装するのがいいのかな?

Trackback address for this post

Trackback URL (right click and copy shortcut/link location)

Feedback awaiting moderation

This post has 1 feedback awaiting moderation...


Form is loading...