mltsy
mltsy

Reputation: 7084

Why are there no rake tasks in this mongoid Rails 3 project?

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

The public repo above is a community coding project we're working on for Austin Community Gardens, and it's a fairly simple project so far, but for some reason rake db:seed doesn't work ("Don't know how to build task db:seed"), and when you run rake -T it reveals no rake tasks at all.

MongoID documentation says it provides most of the usual DB-related rake tasks - I can't figure out why they're not there.

Upvotes: 4

Views: 2019

Answers (2)

Robert Reiz
Robert Reiz

Reputation: 4432

I had the similar problem with Rails 3.X, although the mongoid Gem was included in my Gemfile. I could solve the problem by explicitly requiring the database.rake file from the mongoid gem. I added this 2 lines to my Rakefile:

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

That works for me.

Upvotes: 6

Dominic Tancredi
Dominic Tancredi

Reputation: 42342

Had the exact same issue.

Realized I never added "mongoid" to my Gemfile. This fixes it:

gem 'mongoid'

It will add these rake tasks:

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

Upvotes: 3

Related Questions