Ruby-GetText-Packageで The error occurred while evaluating nil.[]

Ruby-GetText-Packageを導入したら、

/!\ FAILSAFE /!\  Fri Mar 14 19:36:24 +0900 2008
  Status: 500 Internal Server Error
  You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
    /usr/lib/ruby/1.8/cgi.rb:1165:in `[]'

というエラーが出るようになりました。

gettextでinternal server error – cracchoの日記」経由で「Using ruby-gettext with Edge Rails」を見て、解決。

次のコードを「config/environment.rb」の最後にでも追加する。

class CGI
  module QueryExtension
    alias index_without_fix :[]
    def [] (key)
      return nil unless @params[key]
      index_without_fix(key)
    end
  end
end

原因は、Rubyのバグ。
Ruby 1.8.6では修正されているそうです。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください