Prev | Current Page 426 | Next

Brad Ediger

"Advanced Rails"

storage_used) %>, and your limit is
<%= human_size(user.account.quota) %>.
Please reduce your usage within 5 days or we will reduce it for you.
Regards,
The Management
Now, this Mailer class can be used just as if it were inside a Rails application. We??™ll
look at one possible application for this next.
Custom Rake tasks
Rake is best known in Rails for its purposes in testing. Rake is used to kick off Rails
tests, but also to perform administrative functionality (database maintenance and
migrations, managing temporary files and sessions, and the like). We can easily
extend Rake to handle any application-specific maintenance we need to do; in this
case, to find users who are over their quota and send them a nasty email. (For simplicity,
we will abstract away some of the details of finding those users.)
Here is a custom Rakefile that provides the email functionality:
require 'rake'
# Mailer setup commands from above
require 'mailer_config'
# ActiveRecord setup, not shown
require 'ar_users'
Contributing to Rails | 289
# User administration tasks go in a separate namespace
namespace :users do
desc "Send a nasty email to over-quota users"
task :send_quota_warnings do
users = User.find(:all).select{|u| u.storage_used > u.account.quota }
users.each do |user|
Mailer.deliver_quota_exceeded_notification(user)
end
end
end
We can now kick off the email with one command from the project??™s directory:
rake users:send_quota_warnings
Receiving email
The ActionMailer documentation includes instructions on how to receive incoming
email using Rails and ActionMailer.


Pages:
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438