Hatena::ブログ(Diary)

兀兀 -雑多編- このページをアンテナに追加 RSSフィード

2008-12-01

file_columnプラグインでNameError

| 06:56 | file_columnプラグインでNameErrorを含むブックマーク file_columnプラグインでNameErrorのブックマークコメント

Rails 2.2.2でfile_columnプラグインを使うと、

uninitialized constant FileColumn::ClassMethods::Inflector

というエラーが発生し使えない。

どうやら、以下のソースの「Inflector.underscore(self.name).to_s,」の部分が良くないらしい。

  • vender/plugins/file_column/lib/file_column.rb
    def file_column(attr, options={})
      options = DEFAULT_OPTIONS.merge(options) if options
      
      my_options = FileColumn::init_options(options, 
                                            Inflector.underscore(self.name).to_s,
                                            attr.to_s)
      
      state_attr = "@#{attr}_state".to_sym
      state_method = "#{attr}_state".to_sym

おそらく、「Inflector.underscore(self.name).to_s」の部分は、self.nameが表すシンボルをアンダースコア区切りの文字列にしたいんだと思うので、以下のようにString#underscoreメソッドを使うことで、回避してみた。

  • vender/plugins/file_column/lib/file_column.rb
    def file_column(attr, options={})
      options = DEFAULT_OPTIONS.merge(options) if options
      
      my_options = FileColumn::init_options(options, 
                                            self.name.to_s.underscore,
                                            attr.to_s)
      
      state_attr = "@#{attr}_state".to_sym
      state_method = "#{attr}_state".to_sym

動かしてみたところ、うまくいっているようだ。:-)