Rails 4 Error with every command “`load': no implicit conversion of nil into String” (Mac OS X 10.9)

匿名 (未验证) 提交于 2019-12-03 02:23:02

问题:

I've just installed a fresh Ruby on Rails dev stack on my new Macbook, which runs Mac OS X 10.9 Mavericks.

Here is my stack:

  • Xcode command line tools
  • Homebrew
  • Rbenv
  • Bundler
  • Ruby 2.1.0
  • Rails 4.1.1

I ran rails new test_app to generate a first test app. This command successfully completed, but since it, every Rails command I try in my CLI returns this kind of error message:

$ test_app > bin/rails server  /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `load': no implicit conversion of nil into String (TypeError)     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client/rails.rb:27:in `call'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client/command.rb:7:in `call'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/client.rb:26:in `run'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/bin/spring:48:in `<top (required)>'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `load'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/spring-1.1.3/lib/spring/binstub.rb:11:in `<top (required)>'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'     from /Users/me/Documents/[PERSONNEL]/dev/test_app/bin/spring:16:in `<top (required)>'     from bin/rails:3:in `load'     from bin/rails:3:in `<main>' 

Same error while trying to start a console:

$ test_app > bin/rails c  /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load': no implicit conversion of nil into String (TypeError)     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'     from /Users/me/.rbenv/versions/2.1.0/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'     from -e:1:in `<main>' 

The bin/rake are working partially (I can use bin/rake routes but migrations are not working).

My last try was to install XCode, but it didn't solve it.


UPDATE: the command bundle exec rake rails:update:bin as mentioned bellow solve the problem for project, but needed to be executed on every new problem. The problem seems to be deeper.

回答1:

OK I found solution.

I've cleaned my mac too. and I got same error.

rails_root/bin folder is not there?

Try below

bundle exec rake rails:update:bin



回答2:

I have the same problem. Short exploration follows below.

First of all, I have [] in the root path for my application. The error during rails s command

psylone@wizard:~/ruby-rails[code]/context$ rails s /home/psylone/.rvm/gems/ruby-2.2.0/gems/spring-1.2.0/lib/spring/client/rails.rb:30:in `load': no implicit conversion of nil into String (TypeError) 

is in spring gem here: https://github.com/rails/spring/blob/master/lib/spring/client/rails.rb#L27

That's because if Dir.glob contains [] in the path argument the result will be an empty array. So it's necessary to escape [] in the path argument for Dir.glob method. I think about something like this:

# Instead of line 27 in spring/client/rails.rb require 'shellwords' path = Shellwords.escape(Spring.application_root_path) << "/{bin,script}/rails" load path 

After this fix I've found rails s command works fine. But rails c command still causes an error. Probably the answer has the same nature.

So, the simplest way to avoid this error - rename the root path for your application (without [] characters).



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