当我正在创建一个新的rails应用程序时,在跳过活动记录以便稍后使用mongodb时,没有db目录,通过此命令。
rails new app-name --skip-active-record
其中rails new app-name
按预期创建了db。因此,rake db:create
或rake db:migrate
预计不会采取行动。我需要修改/db/seeds.rb
&我找不到。
我尝试了一些帖子修复,没有带来丢失的目录。我是铁杆的新手。我错过了什么吗?感谢您的合作。
答案 0 :(得分:4)
通过在新命令中包含--skip-active-record
,您告诉Rails不生成数据库文件,如果您想使用MongoDB,这是正确的!
接下来,您需要从gemfile中删除sqlite gem并将MongoDb gem添加到gem文件中。 Here is the Ruby Gems page for MongoDB,只需从那里复制gemfile引用并将其粘贴到gemfile中。您总是需要在更改gemfile后运行bundle
命令
然后您运行rails g mongoid:config
并且rails会为您生成config/mongoid.yml
。
以下是参考文章:https://gorails.com/guides/setting-up-rails-4-with-mongodb-and-mongoid
答案 1 :(得分:0)
MongoDB没有架构,因此您不需要迁移。这就是无模式数据库的重点。
db/seeds.rb
只是运行rake db:seed
*时执行的普通Ruby文件。您可以通过运行$ touch db/seeds.rb
来创建它。
它没什么神奇之处。
如果您使用的是Mongoid,则运行时会生成所需的一切:
$ rails g mongoid:config
所以放松一下。