Cannot launch rails server - uninitialized constants Sprockets::Rails::VERSION::(NameError)

假如想象 提交于 2019-12-10 17:04:26

问题


I am simply trying to go through the railsapps.org Learn Ruby on Rails book online. I have everything installed and am stuck at "Launching the Web Server" in the tutorial.

When I execute '$ rails server', I get the following:

trick420$ rails server
=> Booting WEBrick
=> Rails 4.1.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
Exiting
/Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/sprockets-rails-2.1.2/lib/sprockets/railtie.rb:77:in `block in <class:Railtie>': uninitialized constant Sprockets::Rails::VERSION (NameError)
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:36:in `call'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/activesupport-4.1.0/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/application/finisher.rb:64:in `block in <module:Finisher>'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/initializable.rb:30:in `run'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /Users/trick420/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/application.rb:288:in `initialize!'
from /Users/trick420/learn-rails/config/environment.rb:5:in `<top (required)>'
from /Users/trick420/learn-rails/config.ru:3:in `require'
from /Users/trick420/learn-rails/config.ru:3:in `block in <main>'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
from /Users/trick420/learn-rails/config.ru:in `new'
from /Users/trick420/learn-rails/config.ru:in `<main>'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:49:in `eval'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:49:in `new_from_string'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/rack-1.5.2/lib/rack/builder.rb:40:in `parse_file'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/rack-1.5.2/lib/rack/server.rb:277:in `build_app_and_options_from_config'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/rack-1.5.2/lib/rack/server.rb:199:in `app'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/commands/server.rb:50:in `app'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/rack-1.5.2/lib/rack/server.rb:314:in `wrapped_app'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/commands/server.rb:130:in `log_to_stdout'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/commands/server.rb:67:in `start'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:81:in `block in server'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `tap'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:76:in `server'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/railties-4.1.0/lib/rails/commands.rb:17:in `<top (required)>'
from /Users/trick420/learn-rails/bin/rails:8:in `require'
from /Users/trick420/learn-rails/bin/rails:8:in `<top (required)>'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/spring-1.1.2/lib/spring/client/rails.rb:27:in `load'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/spring-1.1.2/lib/spring/client/rails.rb:27:in `call'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/spring-1.1.2/lib/spring/client/command.rb:7:in `call'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/spring-1.1.2/lib/spring/client.rb:26:in `run'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/spring-1.1.2/bin/spring:48:in `<top (required)>'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/spring-1.1.2/lib/spring/binstub.rb:11:in `load'
from /Users/trick420/.rvm/gems/ruby-2.1.1@learn-rails/gems/spring-1.1.2/lib/spring/binstub.rb:11:in `<top (required)>'
from /Users/trick420/learn-rails/bin/spring:16:in `require'
from /Users/trick420/learn-rails/bin/spring:16:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'

I have no ideal what the issue is as I know nothing about Rails or Ruby at this point. Quite the barrier to entry, no? It appears that there is a problem in the gem sprockets-rails, but I have no idea how to deal with that or where to start as I haven't even got started with rails.


回答1:


https://github.com/rails/sprockets-rails/issues/131

Wait for a fix to be released or simply add to your Gemfile

gem 'sprockets-rails', :require => 'sprockets/rails/version'



回答2:


The fix to sprokets-rails has been added. Use

gem update

to update your gems.

sprockets-rails should be at version 2.1.3

Then in your gemfile.lock in your Rails app, modify the following line to the updated gem version:

sprockets-rails (2.1.3)

Run

bundle install

and in the output, confirm it says:

Using sprockets-rails 2.1.3



回答3:


The sprockets-rails team released a broken version (version 2.1.2) of the sprockets-rails gem on April 11, 2014. They released a fixed version 2.1.3 later the same day.

If you've closed your terminal window, open a new one and navigate with Unix "cd" commands to the project directory where you are building your Rails application. Update the sprockets-rails gem (and any others that are outdated) by running:

$ bundle update

Then you can continue where you were.

Good luck with learning Rails (it is not always this difficult). And welcome to Stack Overflow. Be sure to select an answer as correct to encourage the people who have helped.




回答4:


I had to explicitly add my sprockets gem to the gemfile with the version number in order to get it to work, i.e.

gem 'sprockets', '~> 2.2.1'


来源:https://stackoverflow.com/questions/23021236/cannot-launch-rails-server-uninitialized-constants-sprocketsrailsversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!