2013-01-02 20 views
0

我在Ruby 1.9.3和Rails 3.0.11上。我最近安裝了Draper(0.12.0)gem,但我無法運行它的生成器。我收到以下錯誤,當我嘗試在Post模型運行生成器: -無法運行Draper的rails generator

rails generate decorator Post 
/home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.11/lib/active_support/whiny_nil.rb:48:in `method_missing': undefined method `config' for nil:NilClass (NoMethodError) 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/draper-0.12.0/lib/draper/railtie.rb:6:in `block in <class:Railtie>' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/railtie.rb:189:in `call' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/railtie.rb:189:in `each' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/railtie.rb:189:in `load_generators' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/application.rb:147:in `block in load_generators' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/application/railties.rb:11:in `each' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/application/railties.rb:11:in `all' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/application.rb:147:in `load_generators' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/generators.rb:319:in `load_generators_from_railties!' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/generators.rb:278:in `lookup' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/generators.rb:141:in `find_by_namespace' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/generators.rb:161:in `invoke' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/commands/generate.rb:10:in `<top (required)>' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:239:in `require' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:239:in `block in require' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:225:in `block in load_dependency' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:593:in `new_constants_in' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:225:in `load_dependency' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.11/lib/active_support/dependencies.rb:239:in `require' 
    from /home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.0.11/lib/rails/commands.rb:17:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

任何投入,我如何能調試這將是很有益的。

謝謝。

回答

0

問題是在v0.12.0本節(您使用的是一個)https://github.com/drapergem/draper/blob/v0.12.0/lib/draper/railtie.rb#L5-L8

當我看到主分支,他們改變代碼的樣子:https://github.com/drapergem/draper/blob/master/lib/draper/railtie.rb#L5-L10

你應該升級你的布店寶石到最新版本,看看錯誤是否仍然存在。

+0

謝謝,這工作(我用最新的寶石)。我只是好奇地學習一件事..你究竟能夠調試出所有可能引發錯誤的文件「draper/lib/draper/railtie.rb」是一些事情發生的確切文件錯了。此外,你指的是該文件的第6行正確的錯誤的Rails版本導致上述問題,對不對? – boddhisattva

+0

你可以從你發佈的堆棧跟蹤中看到這個。 'method_missing'錯誤通常意味着某些代碼被破壞,因此無法執行。這就是我首先檢查堆棧跟蹤的最頂部的部分。如果你從上到下工作通過堆棧跟蹤,你將開始:/home/mohnish/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.0.11/lib/active_support/whiny_nil。 rb:48這是一個來自rails的補丁,通常不是問題本身。下一行是draper gem:「/draper/railtie.rb:6」,冒號後可以看到行號。 –

+0

謝謝@Yves。 – boddhisattva