[英]rails server works but “rails console” not working
我正在研究Rails項目。 使用命令“ bundle exec rails s”,我可以啟動本地服務器,但是,“ bundle exec rails c”會引發以下錯誤:
/Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler/setup (LoadError)
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/commands.rb:33:in `<module:Spring>'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/commands.rb:4:in `<top (required)>'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:77:in `preload'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:143:in `serve'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:131:in `block in run'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:125:in `loop'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application.rb:125:in `run'
from /Users/wh026399/healthelife_web/vendor/bundle/gems/spring-1.6.2/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/wh026399/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'
[更新]:事實證明,在Gemfile中注釋掉“彈簧”將解決此問題。
您是否嘗試過gem update --system
? 您可能需要rubygems的更新版本。
如果您使用rvm,請使用以下命令設置默認的Ruby版本,這樣它將獲取正確的Ruby版本。 設置默認值后,您可能需要運行bundle install / gem install rails -v 4.2.5
rvm --default 2.2.2
好吧,在遇到與海報相同的問題后,我遇到了這個問題。 他的更新建議從Gemfile中刪除spring幫助我走上了正確的軌道。 對我來說,問題是我引入了一個新的環境變量,但spring並沒有采用。 當您從Gemfile中刪除spring時,它會阻止您的應用使用spring進程, 但實際上並沒有停止spring進程,因此將其重新添加,進行捆綁安裝或其他任何操作仍會使您運行相同的spring進程。
要查看這是否可能是您的問題,您可以檢查bin/spring status
並查看spring是否在后台運行以及是否已經運行了一段時間。
解決方案(至少對我而言):重新啟動spring
bin/spring stop
rails c
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.