0

当我尝试加载 rails 控制台时,我突然收到以下错误消息。我最近刚刚将数据库切换到 postgres,这给我带来了很多问题(尽管我必须承认我比 mysql 更喜欢它!),所以我假设这与此有关。有任何想法吗?

y (Errno::ENOENT)/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require': No such file or directory - /usr/local/lib/?
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processing.rb:3:in `<top (required)>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:5:in `<top (required)>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/environment.rb:1:in `<top (required)>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.10/lib/sprockets/railtie.rb:23:in `block in <class:Railtie>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:30:in `run'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:54:in `each'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:136:in `initialize!'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/benyorke/rubystore/config/environment.rb:6:in `<top (required)>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:103:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:103:in `require_environment!'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
4

2 回答 2

0

我相信这可能是 Ruby 1.9.3-p327 的一个错误,刚刚由 Ruby 1.9.3-p385 修复。升级到 1.9.3-p385 会为您解决问题吗?

此错误消息中似乎很奇怪,并且与我一直遇到的问题类似,是路径末尾的问号:No such file or directory - /usr/local/lib/?. 几周前从 1.9.3-p194 升级到 1.9.3-p327 后,我收到了与 ruby​​ 的 require 和带有问号、符号或其他随机字符的路径相关的类似奇怪错误消息。然而,这些问题非常零星,而且大约在同一时间我们遇到了一些硬件故障,因此很难追踪。

今天这个问题开始在一个特定的上下文中持续发生,所以我能够做一些额外的调试。更新到 1.9.3-p385 似乎已经修复了它,但鉴于我遇到的问题的零星性质,我并不完全 100% 这实际上是修复。我也不完全确定这是否与您遇到的问题相同。路径中的神秘问号只是让它看起来可能是相关的。以下是我们遇到的错误类型的几个示例:

No such file or directory - /srv/shared/rails/internal/admin/vendor/bun@

No such file or directory - /srv/shared/rails/internal/admin/vendor?

如果它与我遇到的相同问题完全相关,但 1.9.3-p385 升级没有解决它,还有一些其他注意事项或需要探索的东西:

  • 我今天能够在 1.9.3-p327 和 1.9.3-p374 上重现此问题。但是,1.9.3-p194、1.9.3-p286 和 1.9.3-p385 上似乎不存在该问题。
  • 您是否在 gem 加载路径中的任何地方使用符号链接?例如,我们使用 Bundler 将 gems 安装到vendor/bundle每个应用程序内的本地路径中。但vendor/bundle实际上是指向另一个位置的符号链接(这与 Capistrano 部署设置有关)。我相信符号链接可能在起作用。在今天的测试中,如果我没有使用符号链接,那么问题在所有版本的 ruby​​ 上都消失了。
  • 你使用bundler-exec吗?在另一个偶尔发生此问题的情况下,绕过别名 bundler-exec 似乎也能神奇地解决问题,但今天的问题甚至没有触及 bundler-exec,所以我不太确定。
  • 大多数情况下,我们的问题是非常随机的(在尝试运行相同命令几次后它会消失),但在少数情况下,问题会持续一个小时或更长时间才消失。
  • 关于我们系统的一些信息:
    • 64 位红帽企业 Linux 6
    • 捆绑器 1.2.3
    • Rubygems 1.2.5(也发生在 1.2.4 下)
    • rbenv

但就像我说的,这个问题也恰好与我们端的一些硬件磁盘故障和一般服务器不稳定同时发生,所以我不确定这是 Ruby 问题还是发生了什么。但希望 1.9.3-p385 能够真正修复它。

于 2013-02-09T04:19:24.600 回答
0

Sorry for not updating this thread - I have actually been working on this in the background for a few weeks now. I couldn't find ANY information on this online, so I'm going to post as detailed of a solution as I can.


The Issues

The issues I was having was that I could not access rails console, and I had to manually start the postgres server every-time I restarted my machine. My solutions to that, as I have worked with this for a few weeks were

In regards to the console I used herokus console. By pushing my app to heroku (which is free) not only could I view it on the web (any machine) but on my machine I could run

$ heroku run console

and get access to a console. Now this isn't a perfect solution in anyway as I can't manipulate data on my machine but it saved me many times

In regards to the server I ran

$ brew info postgres

which gave me the commands to manually restart the server

You should reload postgresql:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

The Solution

To be honest, I have run every command I can find dozens of times, and just today got it working. I don't know if I was making typos, doing it in an ineffective order, mixing up pg/postgres/postgresql or what but what I did below worked

When using this solution, it will erase all databases. Migrations will be able to rebuild the structure, but any data will be lost

1. Updated Homebrew

$ brew update

If you don't have home-brew, check out this page for instructions to install (saved my neck with many things, including minimagick imagemagick and postgres!): http://mxcl.github.com/homebrew/

2. Removed postgresql

$ brew rm postgresql --force

3. Installed postgreql

$ brew install postgresql

This is the first step to reference postgres. When looking online, I ran across commands that used postgresql, postgres, and pg. Postgresql refers to the actually PostgreSQL program. postgres and pg are ruby gems, which we will get to later

4. Ran suggested commands

After running "$ brew install postgres" there is a lot of information given to you. Make sure to read through it, as it will suggest what commands to run. Use these suggestions to find the commands I reference below. If you need to access this information later simply run

$ brew info postgresql

To initialize the database

$ initdb file/path

Set up the autolauncher

$ cp file/path ~ LaunchAgents/file/path

Launch postgresql initially

$ launchctl load file/path
$ pg_ctl-D file/oath

5. Download Postgres.app

Although to my knowledge this seems redundant, this is what got it to work on my mac. visit http://postgresapp.com to download

6. Install gems

There are two gems - postgres and pg. I required pg in my gemfile and ran a bundle install command, however it still gave me issues until I installed postgres on my machine - even though it is not required in my gemfile, rails console wont seem to work without it atleast installed

In the gem file

gem 'pg'

Run a bundle install command in a terminal window

$ bundle install

Sudo install the postgres gem

$ sudo gem install postgres

At this point everything should be working. You should be able to restart the machine and not have any problems!

于 2013-02-21T01:04:30.357 回答