【问题标题】:Why are there no rake tasks in this mongoid Rails 3 project?为什么这个 mongoid Rails 3 项目中没有 rake 任务?
【发布时间】:2012-07-15 16:22:20
【问题描述】:

https://github.com/memphis518/Garden-Dating-Service

上面的公共 repo 是我们正在为 Austin Community Gardens 开发的社区编码项目,到目前为止它是一个相当简单的项目,但由于某种原因 rake db:seed 不起作用(“不知道如何build task db:seed"),当你运行 rake -T 时,它会显示 no rake 任务。

MongoID 文档说它提供了大多数常见的与 DB 相关的 rake 任务 - 我不知道为什么它们不存在。

【问题讨论】:

    标签: ruby-on-rails-3 rake mongoid


    【解决方案1】:

    我在使用 Rails 3.X 时遇到了类似的问题,尽管我的 Gemfile 中包含了 mongoid Gem。我可以通过明确要求 mongoid gem 中的 database.rake 文件来解决这个问题。我在我的 Rakefile 中添加了这 2 行:

    spec = Gem::Specification.find_by_name 'mongoid'
    load "#{spec.gem_dir}/lib/mongoid/railties/database.rake"
    

    这对我有用。

    【讨论】:

    • 谢谢!我想知道,因为我的 Gemfile 中也有它:D
    【解决方案2】:

    遇到了完全相同的问题。

    意识到我从未在我的 Gemfile 中添加“mongoid”。这解决了它:

    gem 'mongoid'
    

    它将添加这些 rake 任务:

    rake db:drop                    # Drops all the collections for the database for the current Rails.env
    rake db:mongoid:create_indexes  # Create the indexes defined on your mongoid models
    rake db:mongoid:drop            # Drops the database for the current Rails.env
    rake db:mongoid:remove_indexes  # Remove the indexes defined on your mongoid models without questions!
    rake db:reseed                  # Delete data and seed
    rake db:seed                    # Load the seed data from db/seeds.rb
    rake db:setup                   # Create the database, and initialize with the seed data
    

    【讨论】:

    • 我在 Gemfile 中肯定有 mongoid。奇怪的是仍然无法正常工作 - 尝试克隆它并亲自查看! ;)
    • 您是否尝试“捆绑更新”或“捆绑安装”以确保安装了 mongoid gem
    • 为我工作。我认为它们会被添加,因为我在 gemspec 中有 mongoid 作为依赖项。
    猜你喜欢
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 1970-01-01
    相关资源
    最近更新 更多