注释gem rails配置给出错误

时间:2016-08-02 10:25:16

标签: ruby-on-rails-4 annotate

Ruby:2.3.0p0

Rails版本:4.2.6

注释宝石版:2.7.1

在做rails g annotate:install时会给我这个错误:

(erb):34:in `template': uninitialized constant AnnotateModels (NameError)
from /Users/newput/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/erb.rb:864:in `eval'
from /Users/newput/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/erb.rb:864:in `result'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/file_manipulation.rb:116:in `block in template'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:53:in `render'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:62:in `block (2 levels) in invoke!'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:62:in `open'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:62:in `block in invoke!'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/empty_directory.rb:116:in `invoke_with_conflict_check'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:60:in `invoke!'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions.rb:94:in `action'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/create_file.rb:25:in `create_file'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/thor-0.19.1/lib/thor/actions/file_manipulation.rb:115:in `template'
from /Users/newput/.rvm/gems/ruby-2.3.0/gems/annotate-2.7.1/lib/generators/annotate/install_generator.rb:9:in `copy_tasks'

1 个答案:

答案 0 :(得分:4)

我不确定这是否解决了您的错误,但我通过以下步骤得到了同样的错误:

  $ rails new hi
  $ cd hi
  $ echo "gem 'annotate', '2.7.1', require: false" >> Gemfile
  $ bundle
  $ rails g annotate:install
  Running via Spring preloader in process 29328
        create  lib/tasks/auto_annotate_models.rake
  (erb):34:in `template': uninitialized constant AnnotateModels (NameError)
          from /home/hibariya/.rbenv/versions/2.3.0/lib/ruby/2.3.0/erb.rb:864:in `eval'
          from /home/hibariya/.rbenv/versions/2.3.0/lib/ruby/2.3.0/erb.rb:864:in `result'
          from /home/hibariya/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/actions/file_manipulation.rb:116:in `block in template'
  ...

我认为可以通过提前要求annotate-gem来修复此错误。 因此,当我从Gemfile中的require: false中删除gem 'annotate', '2.7.1', require: false时,错误已得到修复。