【问题标题】:RoR: Error when doing rake command db:create => rake aborted! no such file to load -- initializerRoR:执行 rake 命令时出错 db:create => rake 中止!没有要加载的文件——初始化程序
【发布时间】:2010-09-09 08:27:45
【问题描述】:

我刚刚安装了一个全新版本的 Ubuntu 10.04,并希望让我的 Rails 项目正常运行。我检查了一个 rails 项目 2.3.3 并使用典型的 sqlite-settings 填写了 databasye.yml 文件:

# SQLite version 3.x
#   gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
  adapter: sqlite3
  database: db/pictrs_development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/pictrs_test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/pictrs_production.sqlite3
  pool: 5
  timeout: 5000

当我跑步时:

rake db:create

我收到以下错误:

helex@mg:~/Downloads/pictrs_on_rails$ rake db:migrate
(in /home/helex/Downloads/pictrs_on_rails)
rake aborted!
no such file to load -- initializer
/home/helex/Downloads/pictrs_on_rails/Rakefile:4:in `require'
(See full trace by running task with --trace)

rake db:create --trace 的输出是:

rake aborted!
no such file to load -- initializer
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
/home/helex/Downloads/pictrs_on_rails/config/boot.rb:55:in `load_initializer'
/home/helex/Downloads/pictrs_on_rails/config/boot.rb:38:in `run'
/home/helex/Downloads/pictrs_on_rails/config/boot.rb:11:in `boot!'
/home/helex/Downloads/pictrs_on_rails/config/boot.rb:110
/home/helex/Downloads/pictrs_on_rails/Rakefile:4:in `require'
/home/helex/Downloads/pictrs_on_rails/Rakefile:4
/usr/lib/ruby/1.8/rake.rb:2383:in `load'
/usr/lib/ruby/1.8/rake.rb:2383:in `raw_load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2017:in `load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:2016:in `load_rakefile'
/usr/lib/ruby/1.8/rake.rb:2000:in `run'
/usr/lib/ruby/1.8/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/1.8/rake.rb:1998:in `run'
/usr/bin/rake:28

rake 似乎在加载 Rakefile 的以下行时遇到问题:

require(File.join(File.dirname(__FILE__), 'config', 'boot'))

我在 ubuntu 9.10 下设置了相同的项目,但在执行 rake 任务时收到错误消息,告诉我为项目安装特定的 gem,因此很容易修复。我创建了其他新项目,它们都起作用了。其实我不知道在哪里寻找错误。我使用了不同的 ruby​​gems 版本,并从我的谷歌搜索中尝试了各种东西。

这是我的宝石清单:

*** LOCAL GEMS ***

abstract (1.0.0)
actionmailer (3.0.0)
actionpack (3.0.0)
activemodel (3.0.0)
activerecord (3.0.0)
activeresource (3.0.0)
activesupport (3.0.0)
arel (1.0.1)
authlogic (2.1.6)
aws-s3 (0.6.2)
barby (0.4.0)
builder (2.1.2)
bundler (1.0.0)
columnize (0.3.1)
configuration (1.1.0)
daemons (1.1.0)
erubis (2.6.6)
fastthread (1.0.7)
gravatar (1.0)
haml (3.0.18)
heroku (1.10.0)
i18n (0.4.1)
json_pure (1.4.6)
launchy (0.3.7)
libxml-ruby (1.1.4)
linecache (0.43)
log4r (1.1.8)
macaddr (1.0.0)
mail (2.2.5)
memcache-client (1.8.5)
mime-types (1.16)
money (3.0.5)
mysql (2.8.1)
pg (0.9.0)
polyglot (0.3.1)
prawn (0.8.4)
prawn-core (0.8.4)
prawn-layout (0.8.4)
prawn-security (0.8.4)
prawnto (0.0.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.4)
rails (3.0.0)
railties (3.0.0)
rake (0.8.7)
rest-client (1.6.1, 1.4.2)
rmagick (2.13.1)
ruby-debug (0.10.3)
ruby-debug-base (0.10.3)
ruby-debug-ide (0.4.10)
rubygems-update (1.3.7)
rubyzip (0.9.4)
sqlite3-ruby (1.3.1)
stateless-systems-paypal (2.1.3)
SystemTimer (1.2)
test-unit (2.1.1)
text-format (1.0.0)
text-hyphen (1.0.0)
thor (0.14.0)
treetop (1.4.8)
tzinfo (0.3.23)
uuid (2.3.1)
xml-simple (1.0.12)
ya2yaml (0.30)

在我看来,我已经安装了所有需要的 gem。您能否提供一些新的东西来思考如何解决这个问题?

非常感谢您的宝贵时间。

【问题讨论】:

    标签: ruby-on-rails-3 rake


    【解决方案1】:

    您已安装 Rails 3.0,但您正在尝试运行 Rails 2.3.3 项目。尝试安装与您的项目匹配的 Rails 版本,您可能会没事的。

    【讨论】:

    • 您好,我成功安装了 rails 2.3.3,它现在显示在我的 gem 列表中。如果我现在想运行“rake db:create”,我会得到以下响应:“rake aborted!can't activate rails (= 2.3.3, runtime) for [],已经为 [] 激活 rails-3.0.0 ”。如何仅为该项目设置 rails 版本?也许是符号链接或熟悉的东西?
    • 尝试将RAILS_GEM_VERSION = '2.3.3' 放在config/environment.rb 的顶部。
    • 效果很好,我现在已经学会了如何处理不同的 rails 版本。
    猜你喜欢
    • 1970-01-01
    • 2011-06-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 2013-03-06
    • 1970-01-01
    • 2012-09-16
    • 2012-09-30
    相关资源
    最近更新 更多