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.
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.
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
Related
I'm following this railscast on performance testing, but I'm immediately running into an issue.
My app is rails 3.2.11, so according to the railscast it should include performance testing, but I don't have a folder called 'test' at all. When I run 'rails generate performance_test homepage' nothing happens or is generated. So I created one manually (to exactly match the railscast source code), but when I run rake test:benchmark I get the error
Don't know how to build task 'test:benchmark'
If I add the 'rails-perftest' gem to my gemfile and run bundle, then again try to generate a performance_test nothing happens, and when I then run rake test:benchmark, it throws a different error of
uninitialized constant Rails::SubTestTask
I've been sure to include the following dependencies in my gem file:
gem 'ruby-prof', group: :test
gem 'test-unit', group: :test
Could anyone help advise me what I'm doing wrong? Thanks!
I am not 100% certain on this, but I am guessing that you might not have your application.rb file configured accordingly. Also check your Gemfile.lock file and run the command bundle install because it could also be something funky going on with your Gems and dependencies.
I've got an existing rails app, and I've added an ember front-end. I'm having trouble deploying the new version (which includes Ember for the first time) to Heroku.
The problem is that I'm unable to run rake tasks in production mode.
I discovered this when I tried to rake db:migrate on heroku. I got the following error:
rake aborted!
undefined method `handlebars' for #<Rails::Application::Configuration:0x00000004f0de90>/app/.bundle/gems/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configuration.rb:85:in `method_missing'
/app/config/application.rb:60:in `<class:Application>'
I get the same error if I try to run any tasks locally in production mode, e.g.:
RAILS_ENV=production rake -T
the offending line, from config/application.rb:
config.handlebars.templates_root = 'ember/templates'
for various reasons, I had to move the ember templates down one file level. and it needs to stay there. everything works fine in development mode.
Any idea how I can fix this?
tried upgrading the ember-rails gem. this didn't help. (I'm using 0.12.0)
trick was to move ember-rails gem out of assets group
I'm using minitest for one of my projects, and I can't seem to get the Rake TestTask to actually run the files.
require 'rake'
require 'rake/testtask'
task :mytest do
Rake::TestTask.new do |t|
t.test_files = Dir.glob('test/model/*_test.rb')
t.verbose = true
puts t.inspect
puts '-------------------------------------'
end
end
when I run this task rake mytest, I get the following output :
projects#webdev-local:/home/projects/framework# rake mytest
#<Rake::TestTask:0x00000001775050 #name=:test, #libs=["lib"], #pattern=nil,
#options=nil, #test_files=["test/model/page_model_test.rb",
"test/model/widget_model_test.rb"], #verbose=true, #warning=false, #loader=:rake,
#ruby_opts=[]>
-------------------------------------
As you can see, The task finds the files, but it never actually runs them. How can I get it to run these files?
Using Rails 3.2.8 and ruby 1.9.3
So, two things you might want to check:
1) Make sure you're using the minitest-rails gem
It adds a lot of the test runner tasks we want and need.
https://github.com/blowmage/minitest-rails
2) The contents of your minitest_helper.rb file (a la spec_helper.rb)
You should have some kind of helper file that you're requiring in all your tests. Make sure it looks something like this:
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require "minitest/autorun"
require "minitest/rails"
class ActiveSupport::TestCase
fixtures :all
end
Now that you have that setup, you can run all the tests as follows:
bundle exec rake test
bundle exec rake minitest # alias for test
bundle exec rake minitest:models
# ... etc ...
Is there an environment variable I could leverage in my rails initializers to determine if a rake task is executing ? Like -- rake db:migrate db:seed
I have a bunch of initializers that could be skipped for most rake tasks:
Don't load spring (it's a jruby project)
Don't load the audit observer that breaks the migration
Update:
I'm probably going to regret this later -- but the following seems to work --
In my application.rb -- have added the following:
config.is_rake = (File.basename($0) == 'rake')
Then I am checking for the value later on
config.active_record.observers = :audit_observer unless config.is_rake
Elsewhere in my spring initializer
SPRING_CONTEXT = org.springframework.context.support.FileSystemXmlApplicationContext.new(SPRING_XML_CONFIG_FILES) unless Rails.application.config.is_rake
Based on answer found here
I am working through the Ruby on Rails 3 tutorial book and typed the following on the command line:
rake db:migrate
which produced the following warning.
WARNING: Global access to Rake DSL methods is deprecated. Please Include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method DemoApp::Application#task called at /Users/imac/.rvm/gems/ruby-1.9.2-p180#rails3tutorial/gems/railties-3.0.7/lib/rails/application.rb:215:in `initialize_tasks'
I am not sure what to do about it or how to work with it. I don't know any other command for Rake.
How can I fix this problem?
Adding include Rake::DSL to the Rakefile before the applications load_tasks were called also worked for me.
So in the above user's case before the DemoApp::Application.load_tasks in the Rakefile.
I found this in Stack Overflow question Ruby on Rails and Rake problems: uninitialized constant Rake::DSL. It refers to a #DHH tweet.
Put the following in your Gemfile
gem "rake", "0.8.7"
You may see something like
rake aborted!
You have already activated Rake 0.9.1 ...
I still had a copy of Rake 0.9.1 in my directory so I deleted it.
You can "delete" Rake 0.9.1 by running the following command:
gem uninstall rake -v=0.9.1
If you have multiple versions of the gem installed, you'll be prompted to pick a version.
After 0.9.1 was cleaned out, I ran
bundle update rake
and was finally able to create my database files. I was using rake db:create, but it should work for rake db:migrate as well.
I hope it helps.
I was having the same problem on Windows with the installer. Ruby 1.9.2 and Rails 3.0.9.
Here is what I did:
bundle update rake
bundle show rake
After doing that I was running rake 0.9.2.
Then I updated the Rakefile in application root folder as follows:
require File.expand_path('../config/application', __FILE__)
require 'rake'
# If you named your application something other than SampleApp, change that below
module ::SampleApp
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
SampleApp::Application.load_tasks
As noted in the comment, make sure the name of your app is correct in the two appropriate lines above.
If you are seeing this on later versions of Rails (like 3.+) you may also want to verify that your environment is clean by using RVM http://beginrescueend.com/ and creating a specific ruby & gemset for your projects.
Use an .rvmrc file on a per-project basis, this will guarantee you aren't getting older system gems into your projects. Which has bitten me before.
This prevents having to monkey around with generated Rakefiles & such.
bundle exec rake db:migrate will solve your ruby version issues