Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.
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.
You can get access to your models, and in fact, your whole environment by making tasks dependent on the environment task. This lets you do things like run rake RAILS_ENV=staging db:migrate
.
See "Custom Rake Tasks".
It loads in your Rails environment so you can actually use your models and what not. Otherwise, it has no idea about those things.
So if you made a task that just did puts "HI!"
then you don't need to add the :environment
task to the dependencies. But if you wish to do something like User.find(1)
well that will need it.
Including => :environment
will tell Rake to load full the application environment, giving the relevant task access to things like classes, helpers, etc. Without the :environment
, you won't have access to any of those extras.
Also => :environment
itself does not make available any environment-related variables, e.g. environment
, @environment
, RAILS_ENV
, etc.
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