ウェブサービスを作っています。

DateHelperJa プラグイン を Rails 2.1.0 に完全対応させる

追記(2008/12/21 9:41):
Rails 2.2 では動きません。


先日の話の続きです。
ちゃんとわかった気がするので、エントリにします。


まずは DateHelperJa プラグインをインストールします。

script/plugin install http://softculture.com/rails/plugins/date_helper_ja/


続いて vendor/plugins/lib/date_helper_ja.rb の修正です。

# xxx には year とかが、yyy には 年 とかが入ります。全 6 メソッドの修正
def select_xxx_with_jp_time_unit(datetime, options = {}, html_options = {})
  select_xxx_without_jp_time_unit(datetime, options, html_options).chomp +
    (options[:use_jp_xxx] =! false && !options[:use_hidden] ? 'yyy' : '') + "\n"
end
  • 仮引数に html_options = {} を加える
  • 実引数に html_options を加える
  • && !options[:use_hidden] を加える


110 行目の修正。

def date_or_time_select_with_jp_time_unit(options, html_options = {})


115 行目の修正。

datetime ||= default_time_from_options(options[:default]) unless options[:include_blank]


129 行目に追加。

if datetime && discard[:day] && !discard[:month]
  datetime = datetime.change(:day => 1)
end


あとは、=! を != に全置換して完了です。
最後の全置換は謎ですが、これをやっておかないと :use_jp_xxx オプションが効かないようです。


distance_of_time_in_words メソッドは見てないので動かないかもしれません。
あと、出力形式が変わったためにテストは完全にこけます。(修正はそんなに難しくないかも)