June 21, 2010
This is a follow up post to Rake Tasks 101. In the 101 post we created Rake tasks, setup dependencies and made our tasks reusable by passing in parameters. In Rake Tasks 102 we’ll be building on those practices, interfacing with a Rails environment and leveraging the cron to automate our Rake task.
Our tasks will search Twitter for any mentions of “daneharrigan” and add the most recent to our Tweet model. In this article I’m making a few assumptions. You’re on a Linux/Unix-based machine. You have John Nunemaker’s Twitter gem installed in your Rails project. Lastly, your
Tweet model was built with one of the two commands:
1 2 3 4 5
# rails 2 script/generate model Tweet username:string message:string tweeted_at:datetime # rails 3 rails generate model Tweet username:string message:string tweeted_at:datetime