Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is rake and how it is used in rails?

What is rake and how it is used in Ruby on Rails?

like image 578
Mothirajha Avatar asked Sep 11 '13 09:09

Mothirajha


People also ask

What is the difference between rake and Ruby?

rake is a Make-like program implemented in Ruby. rails is a web framework, which also has some rake tasks. This means that you can have a ruby program with rake but without rails, but not the other way around. By itself, rake will be faster because you don't need to load the whole rails application.

How do you define a rake task?

Rake enables you to define a set of tasks and the dependencies between them in a file, and then have the right thing happen when you run any given task. The combination of convenience and flexibility that Rake provides has made it the standard method of job automation for Ruby projects.


2 Answers

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 ones that build off of each other.

You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks. Each task has a description, and should help you find the thing you need.

It is most often used for administration level tasks that can be scripted. The benefit to using Rake over Make or similar, is that it is a Ruby tool and can interface with your RoR app natively, so Models, data constraints and business rules are all available for use.

Rails comes with a set of predefined Rake tasks that allow you to perform database migrations, generate Rails scaffold files, etc.

like image 150
michaelward82 Avatar answered Sep 18 '22 16:09

michaelward82


Rake utility allows you to create a job/task which uses rails environment. So say, you want to count the votes a user has given to an article and save it somewhere. You write a rake job, in which you can use Rails models and other helpers and get it done without going away from Rails.

like image 36
techvineet Avatar answered Sep 19 '22 16:09

techvineet