What is rake and how it is used in Ruby on Rails?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With