Questions tagged [rake]

Ruby build utility similar to make with build commands defined in pure Ruby.

Rake uses Rakefiles (cf. Makefiles) defined in pure Ruby, the build utility created by the late Jim Weirich. Rule patterns to synthesize implicit tasks are supported and developers can easily specify pre- and post-task dependency chains. Rake includes a library of pre-packaged tasks to make creating Rakefiles easier.

Rake uses Ruby's anonymous function blocks to define various tasks, allowing the use of Ruby syntax. It has a library of common tasks: for example, functions to do common file-manipulation tasks and a library to remove compiled files (the "clean" task). Like Make, Rake can also synthesize tasks based on patterns: for example, automatically building a file compilation task based on filename patterns. Rake is now part of the standard library from Ruby version 1.9 onward.

Sample Rake file

    namespace :pick do
      desc "Pick a random user as the winner"
      task :winner => :environment do
        puts "Winner: #{pick(User).name}"
      end

      desc "Pick a random product as the prize"
      task :prize => :environment do
        puts "Prize: #{pick(Product).name}"
      end

      desc "Pick a random prize and winner"
      task :all => [:prize, :winner]

      def pick(model_class)
        model_class.find(:first, :order => 'RAND()')
      end
    end

Useful links

Implementation specific tags

You can specify your question by adding the implementation you used as a tag.

4366 questions
53
votes
2 answers

What is rake and how it is used in rails?

What is rake and how it is used in Ruby on Rails?
Mothirajha
  • 1,033
  • 1
  • 10
  • 18
53
votes
2 answers

How do I use helpers in rake?

Can I use helper methods in rake?
Sam Kong
  • 5,472
  • 8
  • 51
  • 87
51
votes
15 answers

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

Here is my error: rake aborted! Gem::LoadError: You have already activated rake 10.3.1, but your Gemfile requires rake 10.2.2. Prepending `bundle exec` to your command may solve…
Aaron
  • 6,466
  • 7
  • 37
  • 75
48
votes
4 answers

Rake vs. Thor for automation scripts?

I want to automate things like: Creating a new Ruby on Rails application with pre-selected database, Git initialize it, create a Heroku project, commit all files, etc. Upload all files in folder to another computer through SSH, but do not overwrite…
never_had_a_name
  • 90,630
  • 105
  • 267
  • 383
47
votes
7 answers

How do I force RAILS_ENV in a rake task?

I have this little rake task: namespace :db do namespace :test do task :reset do ENV['RAILS_ENV'] = "test" Rake::Task['db:drop'].invoke Rake::Task['db:create'].invoke Rake::Task['db:migrate'].invoke end …
Sam Saffron
  • 128,308
  • 78
  • 326
  • 506
46
votes
7 answers

How do you skip failed migrations? (rake db:migrate)

I can't seem to find an option or anything that allows me to skip migrations. I know what you're thinking: "you should never have to do that..." I need to skip a migration that makes changes to specific user records that don't exist in my…
hmind
  • 840
  • 1
  • 6
  • 15
46
votes
3 answers

def block in rake task

I got undefined local variable or method 'address_geo' for main:Object with the following rake task. What's the problem with it? include Geokit::Geocoders namespace :geocode do desc "Geocode to get latitude, longitude and address" task :all =>…
Victor
  • 13,010
  • 18
  • 83
  • 146
46
votes
4 answers

# TODO in rails

I had read through a rails book and once found we can add # TODO: and some # stuff in codes, so we can you some rake cmd to look back. My problems is I can't find where are those "# stuff" and "rake cmd" I google and search around, but can't find…
sarunw
  • 8,036
  • 11
  • 48
  • 84
46
votes
1 answer

How to rake db:drop and rake db:create on Heroku?

Possible Duplicate: How to empty DB in heroku I have a Postgres database on Heroku. It is one of the free beta ones. Locally, when testing, I often run rake db:drop && rake db:create && rake db:migrate as a way to reset the database. However,…
Geoff
  • 9,470
  • 13
  • 52
  • 67
44
votes
2 answers

Uninitialized Constant in Rake Tasks

Here's the setup: New Rails app, then put this test_rake.rake in lib/tasks: task :testclass do HelloClass.hello end` Put hello_class.rb in app/models, or in lib/ with this line: config.autoload_paths += %W(#{config.root}/lib) added to…
Andrew Evans
  • 897
  • 2
  • 7
  • 17
44
votes
5 answers

How to detect what causes a deprecation warning in Rake

When I do bundle exec rake -T (or bundle exec rake), I get deprecation warnings: Andrews-Air:nabu agrimm$ bundle exec rake --trace -T [DEPRECATION] `last_comment` is deprecated. Please use `last_description` instead. [DEPRECATION] `last_comment` is…
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
43
votes
6 answers

Ruby on Rails: debugging rake tasks

When I write debugger it does not start: NoMethodError: undefined method `run_init_script' for Debugger:Module from /usr/local/lib/ruby/gems/1.8/gems/ruby-debug-base-0.10.3/lib/ruby-debug-base.rb:239:in `debugger' from (irb):4 If I run rake my:task…
Andrey Kuznetsov
  • 11,640
  • 9
  • 47
  • 70
43
votes
3 answers

How to debug a Rails asset precompile which is unbearably slow

I'm working on a Rails 3.2 project and the assets have increased a fair bit in recent months although I wouldn't consider the project to be large. The assets consist of JS (no coffee-script), and SASS files; we've quite a few images but they've been…
andyroberts
  • 3,458
  • 2
  • 37
  • 40
41
votes
4 answers

Asking questions in rake tasks

I have a rake task that is called from another rake task. In this rake task I need to ask the user for some text input, and then, depending on the answer either continue, or stop everything from continuing (including the calling rake task). How can…
Neil Middleton
  • 22,105
  • 18
  • 80
  • 134
40
votes
2 answers

Why is Rake not able to invoke multiple tasks consecutively?

I have a Rake task which I have simplified below. I'm using Ruby 1.9 on Windows. Perhaps you would like to guess the outcome of calling the Rake task "list_all_levels" below? It should be: "Hello level 1" "Hello level 2" "Hello level 3" But for…
PandaWood
  • 8,086
  • 9
  • 49
  • 54