我想创建一个rails项目,我不需要数据库。
我喜欢以干净的方式做事,不留痕迹,所以我想我会从项目中删除所有类似db的宝石。
我用
启动了我的应用rails new test_app --skip-activerecord
然后我通过注释掉
行来删除与数据库相关的宝石 gem 'sqlite3'
在bundle install
之后,没有出现任何错误,所以我认为一切都很好。
当我尝试生成新控制器时,问题就出现了。
当我输入rails generate controller my_controller
时,我得到了这个大堆栈跟踪
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/connection_handling.rb:50:in `establish_connection'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/base.rb:316:in `<module:ActiveRecord>'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activerecord-4.2.0/lib/active_record/base.rb:26:in `<top (required)>'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.3.6/lib/spring/application.rb:319:in `active_record_configured?'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.3.6/lib/spring/application.rb:251:in `disconnect_database'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.3.6/lib/spring/application.rb:97:in `preload'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.3.6/lib/spring/application.rb:143:in `serve'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.3.6/lib/spring/application.rb:131:in `block in run'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.3.6/lib/spring/application.rb:125:in `loop'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.3.6/lib/spring/application.rb:125:in `run'
from /usr/local/rvm/gems/ruby-2.1.5@rails4/gems/spring-1.3.6/lib/spring/application/boot.rb:18:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
基本上它似乎告诉我,我需要我的sqlite3 gem,但等待:我没有指定我不想在我的项目中使用Active Record吗?为什么抱怨?
我后来发现删除sqlite3 gem也会阻止我做其他事情,例如运行rails g -h
(导致相同的堆栈跟踪)。
这告诉我问题不一定与ActiveRecord有关,但是有些配置文件需要sqlite3,但它在哪里呢?
提前感谢您的帮助。