# TODO in rails

You can use # TODO, # FIXME, and # OPTIMIZE and you can easily get all of these with the following rake task: rake notes In addition to the default annotations, you can always specify and search for your own annotations: rake notes:custom ANNOTATION=ZOMG

def block in rake task

Update: Gotcha This potentially adds the method to global scope and will conflict with any other method with the same name. Look at @Hula_Zell’s answer https://stackoverflow.com/a/44294243/584440 for a better way. Original answer You are defining the method inside the rake task. For getting the function, you should define outside the rake task (outside the task … 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

Rake vs. Thor for automation scripts?

Rake and Thor serve different purposes. Rake is a general build script tool that is project-specific. In other words, you put your rakefile into your project folder and in your project’s source control, and you can create, build and do other automation tasks that are specific to your project in that rakefile. Rake requires a … Read more

Rails: You have already activated rake 10.3.1, but your Gemfile requires rake 10.2.2 (Gem::LoadError)

EDIT 2: You should look at bundle update and change your workflow a little. Refer to this question for further assistance. Original answer This is a simple issue which happens when your gemset has a rake version that is newer than the version number your Gemfile.lock mentions. As is mentioned in the error message, you … Read more

What is rake and how it is used in rails?

Rake is a “software task management tool“, similar to Make, etc. in other systems. See: http://guides.rubyonrails.org/command_line.html#rake Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility ‘make’, and uses a ‘Rakefile’ and .rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated … Read more

Is it possible to make an interactive Rake task?

Something like this might work task :action do STDOUT.puts “I’m acting!” end task :check do STDOUT.puts “Are you sure? (y/n)” input = STDIN.gets.strip if input == ‘y’ Rake::Task[“action”].reenable Rake::Task[“action”].invoke else STDOUT.puts “So sorry for the confusion” end end Task reenabling and invoking from How to run Rake tasks from within Rake tasks?