无法启动Webrick服务器未初始化的常量ActionView :: Helpers :: ActiveM odelHelper(NameError)

时间:2015-08-02 10:55:14

标签: ruby-on-rails ruby gem

我正在阅读Lynda教程,我正在尝试启动一台服务器,但是我收到一条错误说

  

C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionview-4.2.3/lib/action_view/helpers。   rb:40:in'':未初始化的常量ActionView :: Helpers :: ActiveM   odelHelper(NameError)。

之前我确实运行过bundle install。我也复制了这里的宝石文件

C:\Users\berutiel\Documents\sites\tut>bundle install
Resolving dependencies...
Using rake 10.4.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.7.0
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.3
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile 0.6.2
Using nokogiri 1.6.6.2
Using rails-deprecated_sanitizer 1.0.3
Using rails-dom-testing 1.0.6
Using loofah 2.0.2
Using rails-html-sanitizer 1.0.2
Using actionview 4.2.3
Using rack 1.6.4
Using rack-test 0.6.3
Using actionpack 4.2.3
Using globalid 0.3.5
Using activejob 4.2.3
Using mime-types 2.6.1
Using mail 2.6.3
Using actionmailer 4.2.3
Using activemodel 4.2.3
Using arel 6.0.2
Using activerecord 4.2.3
Using debug_inspector 0.0.2
Using binding_of_caller 0.7.2
Using bundler 1.10.6
Using columnize 0.9.0
Using byebug 5.0.0
Using multi_json 1.11.2
Using jbuilder 2.3.1  
Using mysql2 0.3.19
Using thor 0.19.1
Using railties 4.2.3
Using sprockets 3.2.0
Using sprockets-rails 2.3.2
Using rails 4.2.3
Using rdoc 4.2.0
Using sdoc 0.4.1
Using tzinfo-data 1.2015.5
Using web-console 2.2.1
Bundle complete! 8 Gemfile dependencies, 44 gems now installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
  

C:\ Users \ berutiel \ Documents \ sites \ tut> rails server

C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionview- 4.2.3/lib/action_view/helpers.
rb:40:in <module:Helpers>': uninitialized constant    ActionView::Helpers::ActiveM
odelHelper (NameError)
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionview-    4.2.3/lib/action_
view/helpers.rb:4:in <module:ActionView>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionview- 4.2.3/lib/action_
view/helpers.rb:3:in <top (required)>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionview-  4.2.3/lib/action_
view/base.rb:5:in require'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/actionview-4.2.3/lib/action_
view/base.rb:5:in <top (required)>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_co
nsole/template.rb:7:in <class:Template>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_co
nsole/template.rb:6:in <module:WebConsole>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/web-console-  2.2.1/lib/web_co
nsole/template.rb:1:in <top (required)>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_co
nsole.rb:12:in require'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web_co
nsole.rb:12:in <top (required)>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web-co
nsole.rb:1:in require'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/web-console-2.2.1/lib/web-co
nsole.rb:1:in <top (required)>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/r
untime.rb:76:in require'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/r
untime.rb:76:in block (2 levels) in require'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/r
untime.rb:72:in each'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/r
untime.rb:72:in block in require'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/r
untime.rb:61:in each'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler/r
untime.rb:61:in require'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/bundler-1.10.6/lib/bundler.r
b:134:in require'
    from   C:/Users/berutiel/Documents/sites/tut/config/application.rb:7:in <
top (required)>'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/com
mands/commands_tasks.rb:78:in require'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/com
mands/commands_tasks.rb:78:in block in server'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/com
mands/commands_tasks.rb:75:in tap'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/com
mands/commands_tasks.rb:75:in server'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/com
mands/commands_tasks.rb:39:in run_command!'
    from C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/com
mands.rb:17:in <top (required)>'
    from bin/rails:4:in require'
    from bin/rails:4:in <main>'
ource 'https://rubygems.org'

的Gemfile

    # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
    gem 'rails', '4.2.3'
    # Use mysql as the database for Active Record
    gem 'mysql2'
    # Use SCSS for stylesheets
    #gem 'sass-rails', '~> 5.0'
    # Use Uglifier as compressor for JavaScript assets
    #gem 'uglifier', '>= 1.3.0'
    # Use CoffeeScript for .coffee assets and views
    #gem 'coffee-rails', '~> 4.1.0'
    # See https://github.com/rails/execjs#readme for more supported runtimes
    # gem 'therubyracer', platforms: :ruby

    # Use jquery as the JavaScript library
    #gem 'jquery-rails'
    # Turbolinks makes following links in your web application faster. Read    more: https://github.com/rails/turbolinks
    #gem 'turbolinks'
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem 'jbuilder', '~> 2.0'
    # bundle exec rake doc:rails generates the API under doc/api.
    gem 'sdoc', '~> 0.4.0', group: :doc
    gem 'rack', '~> 1.6.4'
    # Use ActiveModel has_secure_password
    # gem 'bcrypt', '~> 3.1.7'

    # Use Unicorn as the app server
    # gem 'unicorn'

    # Use Capistrano for deployment
    # gem 'capistrano-rails', group: :development

    group :development, :test do
    # Call 'byebug' anywhere in the code to stop execution and get a      debugger console
    gem 'byebug'

    # Access an IRB console on exception pages or by using <%= console %> in views
    gem 'web-console', '~> 2.0'
  end

  # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
  gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

2 个答案:

答案 0 :(得分:1)

这很奇怪。您粘贴的错误消息似乎有拼写错误;你可以确认在这个错误消息中“模型”的M和O之间确实存在空格吗?

uninitialized constant ActionView::Helpers::ActiveM odelHelper (NameError) .

无论如何,我会尝试以几种方式对此进行排查:

  1. 您是否可以验证Rails gem是否已安装,并且位于正确的位置?在app目录中,运行bundle show nokogiri以找出gem nokogiri的安装位置(或选择任何其他似乎没有出错的gem),然后运行bundle show rails进行验证Rails安装在同一路径中。
  2. actionview中是否显示Gemfile.lock?此文件是Gemfile的“已编译”版本,并列出了您的应用程序所具有的每个gem依赖项的确切版本。应该安装此处列出的所有内容,然后打开并验证ActionView是否在列表中。它绝对应该是因为rails gem包含/依赖它。
  3. 您可以使用全新的应用重现问题吗?离开你的应用程序目录开始一个全新的应用程序,绑定rails new test_app,然后cd并运行bundle install以安装此应用程序的默认gem,然后运行rails server到看看错误是否像以前一样出现。如果它使用全新的应用程序进行复制,那么您可以在此处提出问题的更具体步骤,以便我们更轻松地进行故障排除。
  4. 祝你好运!使用Rails环境的初始设置可能非常令人沮丧,但它变得更好。

答案 1 :(得分:0)

我经历了这个解决方案,RubyInstaller 2.2.1 and Rails - Rake cannot load Nokogiri

问题得到解决 谢谢大家