没有将nil隐式转换为字符串设计

时间:2013-07-22 19:40:28

标签: ruby-on-rails ruby devise

我是红宝石的新手。我只是想设置Devise。我按照https://github.com/plataformatec/devise的说明进行操作,当我到达rake db:migrate命令时,它告诉我rake已中止并且“没有将nil隐式转换为String”。这令人沮丧,因为我正在做的指南/视频正在做什么,我得到一个错误。

见下面的错误。

User$ rake db:migrate
rake aborted!
no implicit conversion of nil into String
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:24:in `initialize'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:24:in `new'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/sqlite3_adapter.rb:24:in `sqlite3_connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:79:in `retrieve_connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/connection_handling.rb:53:in `connection'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/migration.rb:863:in `initialize'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `new'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate'
/usr/local/rvm/gems/ruby-1.9.3-p392/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

谢谢。

3 个答案:

答案 0 :(得分:2)

很可能是由于config/database.yml文件错误造成的。这是一个常规的:

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/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/test.sqlite3
  pool: 5
  timeout: 5000

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

答案 1 :(得分:1)

我遇到了同样的问题,这是由config/initializers/devise.rb中的以下行引起的:

config.mailer_sender = 'no-reply@' + Rails.application.secrets.domain_name
未设置Rails.application.secrets.domain_name中定义的

secrets.yml,这是导致错误的原因。

答案 2 :(得分:1)

每次我尝试rake install宝石时,Rake都会给我这个消息。它会成功打包gem,然后尝试运行ruby -S gem install pkg/my_gem.version.gem。它会失败。

奇怪的是,从命令行运行命令会成功安装相同的gem。

看到其他人建议重新安装所有宝石,我尝试重新安装rake gem。它似乎修复了它。 (我也重新安装了捆绑器宝石,但我不相信这是问题所在。)