actionview-4.2.4 - uninitialized constant ActionVi

2019-05-26 01:42发布

问题:

C:\Users\Clarion Smith\Documents\Sites\simple_cms>rails server
C:/Ruby22/lib/ruby/gems/2.2.0/gems/actionview-4.2.4/lib/action_view/helpers.rb:40:in `<module:Helpers>': uninitialized constant ActionView::Helpers::ActiveModelHelper (NameError)
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/actionview-4.2.4/lib/action_view/helpers.rb:4:in `<module:ActionView>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/actionview-4.2.4/lib/action_view/helpers.rb:3:in `<top (required)>'
        from C:/Ruby22/lib/ruby/gems/2.2.0/gems/actionview-

My problem is very common in Ruby and Rails. Though I went through different stackoverflow answers, I could not find anything specific which would fix my error.

I tried reinstalling lower version of the railites gem but the same error keeps popping. I tried reinstalling all the gems that were throwing errors and still the problem doesnt seem to go away. Many articles indicated that this is a compatibility issue. But when I tried reinstalling a lower version of the railties gem(4.0.0), the command prompt still asked me to upgrade to the latest version in order to continue. I also installed 'Passenger' web server to check the compatibility and a similar error popped up but this time with the passenger gem. Please look into this accordingly. I am also copying below the gem file.

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use mysql as the database for Active Record
gem 'mysql2'
#Bundle for Passenge r web server
gem 'passenger'
# Use SCSS for stylesheets
#gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets

#gem 'uglifier', '>= 1.3.0'
gem 'rack', '~> 1.6.0'
gem 'rspec-rails', :group => [:development, :test]
# 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

# 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'
end

group :development do
  # 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]

回答1:

I remember fixing this error this way:

  1. Uninstall railties gem.

  2. Then install an older version of the rails gem (4.0.0 in my case because that was the one from the tutorial).

This fixed the issue for me once.

Did you try these steps?



回答2:

Check your Gemfile.lock file for the version of nokogiri used. I experienced the same issue with nokogiri 1.6.6.4. It installs successfully with necessary dlls but for some reason it doesn't play nice on windows.

What worked for me, hope this works for you too

  1. Put gem 'nokogiri', '1.6.6.2' in your gem file
  2. Uninstall other versions of nokogiri
  3. Download nokogiri 1.6.6.2 gem from here compiled by paulgrant999 for ruby 2.2. Both x86 and x64 versions are available, for now. Author states repo will be deleted soon.
  4. Install using command gem install --local path-to-gem/filename.gem
  5. Bundle install in your project directory. It may ask you to run bundle update nokogiri to update dependencies. rails s should now start the server.


回答3:

For me I was able to get around this with

gem pristine --all