无法在 Windows 中访问 Rails 控制台 - LoadError

Cannot access Rails console in Windows - LoadError

我正在使用 JRuby,因为它更适合 Rails、Windows、

上的 SRS Ruby

我的解决方案是在 cmd.exe 或 Powershell(不是 gitbash)中使用 jirb

我试过:

$ rails console
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.

  require at org/jruby/RubyKernel.java:939
    <top> at bin/rails:4

和:

$ bundle exec rails console
uri:classloader:/jruby/kernel/kernel.rb:17: warning: unsupported exec option: close_others
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.

  require at org/jruby/RubyKernel.java:939
    <top> at bin/rails:4

和:

$ jruby.exe -S bundle exec rails console
uri:classloader:/jruby/kernel/kernel.rb:17: warning: unsupported exec option: close_others
Loading development environment (Rails 4.2.4)
Switch to inspect mode.
LoadError: load error: rails/commands -- java.lang.UnsatisfiedLinkError: The operation completed successfully.

  require at org/jruby/RubyKernel.java:939
    <top> at bin/rails:4

我尝试了解决方案“Load error when running rails console”,但是重启电脑没有效果。 bin/spring 没有提到 GEM_HOME。我重新安装了 Rails 和 Spring。

这是因为JRuby吗?

我认为 jruby -S rails console 需要 C 扩展。我找到了另一种使用 JRuby 自己的 jirc 访问控制台的方法。我开始于:

$ jirb
Switch to inspect mode.

然后编辑 ~/.irbrc 以包含

IRB.conf[:PROMPT_MODE] = :SIMPLE

产生了:

$ jirb
Switch to inspect mode.
>>

然后立即退出。这样做:

$ jirb puts 'hello'
Switch to inspect mode.
Errno::ENOENT: No such file or directory - puts
  initialize at org/jruby/RubyFile.java:342
        open at org/jruby/RubyIO.java:1124
        open at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/magic-file.rb:7
  initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/input-method.rb:100
  initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb/context.rb:84
  initialize at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb.rb:426
       start at G:/jruby-9.0.1.0/lib/ruby/stdlib/irb.rb:381
       <top> at G:/jruby-9.0.1.0/bin/jirb:13

由于我的控制台仍然无法正常工作,而且 jirc 没有使用 C 扩展,所以这个问题与那个问题不重复。

是的,我会尝试安装 jruby 来解决这个问题

http://jruby.org/getting-started

然后从项目的根目录执行bundle

TL;DR 在命令提示符中使用 jirb 来执行 Ruby 代码。

我从未下定决心让 rails console 工作。这可能与我的 ruby 安装是 jRuby.

的一部分有关

但是,irbjirb 允许我使用命令提示符或 Powershell 在命令行上执行 Ruby 片段。 GitBash 不工作,说 Switch to inspect mode. 后跟 >> 然后退出。