【问题标题】:Ruby on rails server won't startRuby on rails 服务器无法启动
【发布时间】:2014-07-11 03:09:11
【问题描述】:

我正在尝试在 Rails 上启动服务器,但它无法正常工作,有什么想法可以解释为什么会这样吗?我还没有编辑项目,这是我第一次尝试启动它。我已经重新安装了 gems 并使用了带有一些不同选项的 bundle install ,但都无济于事。我在 Windows 上工作。

C:\Users\Julián\Documents\Sites\simple_cms>rails server
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/comman
ds_tasks.rb:79:in `require': cannot load such file -- C:/Users/Julián/Documents/Sites/simple_cms/config/application (LoadError)
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:79:in `block in server'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `server'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

更新: 我在另一个文件夹上的新项目上运行了相同的命令,没有任何奇怪的字符(例如“á”),也没有成功。这是新的错误。

C:\Users\Public\Sites\simple_cms>rails server
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `require': 126: The specified module could not be found.   - C:/Ruby200-x64/lib/ruby/gems/2.0.0/extensions/x64-mingw32/2.0.0/mysql2-0.3.16/mysql2/mysql2.so (LoadError)

    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.16/lib/mysql2.rb:8:in `<top (required)>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:76:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:72:in `each'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:72:in `block in require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in `each'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/lib/bundler/runtime.rb:61:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.6.3/lib/bundler.rb:132:in `require'        from C:/Users/Public/Sites/simple_cms/config/application.rb:7:in `<top (required)>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:79:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:79:in `block in server'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `tap'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:76:in `server'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.1.4/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

【问题讨论】:

  • 确保该文件存在于:C:/Users/Julián/Documents/Sites/simple_cms/config/application.rb
  • 文件存在,它包含以下内容: require File.expand_path('../boot', FILE) require 'rails/all' Bundler.require(*Rails .groups) 模块 SimpleCms 类 Application

标签: ruby-on-rails ruby windows


【解决方案1】:

看起来command_tasks.rb 找不到您的应用程序文件。这可能是因为路径名。 C:/Users/Julián/Documents/Sites/simple_cms/config/application 好像把你的名字 Julián 误认为是 Julián

【讨论】:

  • 我一开始也是这么想的,所以我在“Public”用户的新文件夹中再次尝试,但我得到了同样的错误
  • 公共用户的输出还有吗?
  • 看新的错误你有安装mysql吗?
  • 似乎其他人也遇到过这个问题,不得不将 `libmysql.dll' 复制到 ruby​​ bin 目录下。 *.com/questions/5164818/…
【解决方案2】:

捆绑安装

可能是错误的,但您肯定缺少 mysql2 gem 或 Rails 加载应用程序所需的 mysql 文件。

如果您在系统上执行bundle install,就会确认这一点 - 我猜mysql gem 会失败


MYSQL Gem

考虑到您在 Windows 上,您可能没有安装 MYSQL2 gem - 标准问题,我们写了一篇关于 here 的教程:

  1. 在您的系统上安装任何MYSQL C-Connector Header files
  2. 使用相关参数安装 mysql2 gem
  3. 将 libmysql.dll 文件复制到您的ruby/bin 目录

C-Connector 头文件对于 Windows 至关重要,因为它们允许您的系统“读取”MYSQL 命令/请求。这些默认不安装,所以你必须自己安装它们(只是安装gem,然后你可以根据需要摆脱它们):

安装此文件,然后可以使用以下安装命令:

gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:\mysql-connector-path"'

应该在您的系统上安装 gem,然后您可以通过将 libmysql.dll 从 mysql 文件的 bin 目录转移到您的 ruby/bin 目录来完成:

【讨论】:

    【解决方案3】:

    可能,以其他方式您应该尝试使用 Linux (Ubuntu) 的虚拟机。 我第一次使用 Windows 开始使用 rails,但操作 gems 和环境非常困难。

    【讨论】: