rails c 在 rails 5 中不工作

rails c not working in rails 5

关于在 rails 5 应用程序中使用终端中的命令

rails c

下面给出了抛出的错误。我不知道这在此处的类似问题中意味着什么,解决方案是使用 spring 停止。我也试过了,但没有,它仍然给出了同样的错误。如果有人能在这里指出错误就太好了。

Running via Spring preloader in process 6457
/Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require': dlopen(/Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle, 9): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib (LoadError)
  Referenced from: /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
  Reason: image not found - /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/readline.bundle
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/irb/completion.rb:10:in `<top (required)>'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:3:in `<top (required)>'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:138:in `require_command!'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:68:in `console'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `block in require'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'
    from /Users/AmanChawla/Desktop/NewApp/bin/rails:9:in `<top (required)>'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'
    from /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'
    from /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/AmanChawla/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'

这是对这个问题的标准修复,试试这个。它应该能让你继续前进

brew rm -f readline

brew install readline

brew link readline --force

这里有一个参考 link rails console doesn't load due to libreadline

我最近在更新 HomeBrew 时遇到了这个问题,我也在使用 rails 5 并找到了这个解决方案,它对我有用:

ln -s /usr/local/opt/readline/lib/libreadline.7.0.dylib /usr/local/opt/readline/lib/libreadline.6.dylib

来源:https://gist.github.com/mcshakes/c87e8adda174c73be354094800b9756d

更新

对于 readline 8 和更新版本,请遵循@Cody Elhard 给出的答案

另一个问题可能是哪个版本的 ruby 在您的路径中 - 请再次检查。

ruby -v
ls -la `which ruby`

然后检查你的路径

我通过简单地添加这个 gem gem 'rb-readline' 和 运行 包解决了这个问题。

rb-readline

作为一般方法,如果由于使用自制程序更新 readline 而发生此错误

通过读取brew install readline

的输出可以找到新版本

我的输出:readline 8.0.0 is already installed and up-to-date

加载错误可以找到旧版本

我的错误(注意7):Library not loaded: /usr/local/opt/readline/lib/libreadline.7.dylib (LoadError)

ln -s new_version/path/to/readline original_version/path/to/readline

在我的例子中,我的命令是

ln -s /usr/local/opt/readline/lib/libreadline.8.0.dylib /usr/local/opt/readline/lib/libreadline.7.dylib