Load error when running rails console

前端 未结 4 1033
广开言路
广开言路 2020-12-11 02:46

I am using rails 4.1 and ruby 2.1.1

Everything works, but when I run rails console I get this error

> rails console
Loading development environmen         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-11 03:15

    If you encounter this problem you should restart you computer. If that does not fix it read on.

    The bin/spring file sets ENV["GEM_HOME"] to a blank string

    bin/spring

    11 ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
    12 ENV["GEM_HOME"] = ""
    13 Gem.paths = ENV
    

    This crashes when running rails console because in line 41

    ENV['GEM_HOME'].split(/\//).last
    

    returns nil if ENV['GEM_HOME'] is blank

    ~/.rvm/rubies/ruby-2.1.1/.irbrc

    39 # Calculate the ruby string.
    40 rvm_ruby_string = ENV["rvm_ruby_string"] ||
    41 (ENV['GEM_HOME'] && ENV['GEM_HOME'].split(/\//).last.split(/@/).first) ||
    42 ("#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" rescue nil) ||
    43 (RUBY_DESCRIPTION.split(" ")[1].sub('p', '-p') rescue nil ) ||
    44 (`ruby -v` || '').split(" ")[1].sub('p', '-p')
    

    rvm uses the string to set the prompt message in the console. If you change line 12 in bin/spring to

    ENV["GEM_HOME"] = "Spring is great!"
    

    You get this nice prompt

    bin/rails c
    Loading development environment (Rails 4.1.0)
    Spring is great! :001 > 
    

    I don't really understand why ENV["GEM_HOME"] is set to a blank string. So, I just change this to get rid of the error. I have posted an issue on the spring github page.

    Beware!

    Any changes to the bin/spring file gets overwritten when you run the spring binstub command

提交回复
热议问题