エラー回避 date_select -- can't convert Symbol into String
環境
Rails 2.1 から Rails 2.2 にバージョンアップしていたら、View の date_select で以下のエラーが出た。
can't convert Symbol into String
なんでだ!?
エラー内容を見ると、
〜/jruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/date_helper.rb:564:in 'select_date'
〜/jruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/date_helper.rb:845:in 'to_date_select_tag'
などなど出ているが、該当箇所のコードを見ても特におかしい点はないような気がする。。。
う〜〜ん、わからない。1日悩む。。
Rails 2.2 から、国際化(i18n)に関する簡単な機能が搭載されるようになった。
validation のメッセージとかを日本語化したかったので、早速 environment.rb の以下の一文を入れていた。
config.i18n.default_locale = :ja
これをコメントアウトしてWebサーバー再起動して実行したところ、date_select は普通に動くではないか!!
これが原因か。。Railsのバグだ。たぶん・・・
というわけで調べたところこんな書き込みを発見!
これを元に、
〜/jruby/lib/ruby/gems/1.8/gems/actionpack-2.2.2/lib/action_view/helpers/date_helper.rb
の以下のコードを
def translated_date_order begin I18n.translate(:'date.order', :locale => @options[:locale]) || [] end end
下のように書き換えたところ
def translated_date_order begin order = I18n.translate(:'date.order', :locale => @options[:locale]) if order.respond_to?(:to_ary) order else [:year, :month, :day] end end end
動いたーー!
というわけで次のRailsのバージョンアップで対応してもらいたい問題だと思います。。
まぁとりあえず動いてよかった。。