Execute bash commands from a Rakefile

I think the way rake wants this to happen is with: http://rubydoc.info/gems/rake/FileUtils#sh-instance_method Example: task :test do sh “ls” end The built-in rake function sh takes care of the return value of the command (the task fails if the command has a return value other than 0) and in addition it also outputs the commands output.

Bundler::GemNotFound: Could not find rake-10.3.2 in any of the sources

bundle config set –local path ‘vendor/cache’ generally fixes it as that is the more common problem. Basically, your bundler path configuration is messed up. See their documentation (first paragraph) for where to find those configurations and change them manually if needed. P.S. If the documentation link is not accessible it might be related to the … Read more

How do I force RAILS_ENV in a rake task?

For this particular task, you only need to change the DB connection, so as Adam pointed out, you can do this: namespace :db do namespace :test do task :reset do ActiveRecord::Base.establish_connection(‘test’) Rake::Task[‘db:drop’].invoke Rake::Task[‘db:create’].invoke Rake::Task[‘db:migrate’].invoke ActiveRecord::Base.establish_connection(ENV[‘RAILS_ENV’]) #Make sure you don’t have side-effects! end end end If your task is more complicated, and you need other aspects … Read more

How do I run a rake task from Capistrano?

A little bit more explicit, in your \config\deploy.rb, add outside any task or namespace: namespace :rake do desc “Run a task on a remote server.” # run like: cap staging rake:invoke task=a_certain_task task :invoke do run(“cd #{deploy_to}/current; /usr/bin/env rake #{ENV[‘task’]} RAILS_ENV=#{rails_env}”) end end Then, from /rails_root/, you can run: cap staging rake:invoke task=rebuild_table_abc

Can’t migrate database after scaffold. Section 2.2 Ruby on Rails Tutorial Michael Hartl

I just ran into this as well. This is due to ActiveRecord 4.2.0.beta4 passing a parameter to Arel::Nodes::BindParam.new. Arel 6.0.0 was just released today. In this version, BindParam does not accept any parameters in it’s initalizer. ActiveRecord has already fixed this on the master branch. Until beta5 is released you’ll need to lock your Gemfile … Read more