Twitter on your maintenance page
I recently started a new project. Because the domain was purchased, one of the first acts of business was a, “Coming Soon,” page. I decided the maintenance/deploy:web:disable page was the perfect solution. I could put it up in production and leave it off in staging without special code shenanigans. It would be re-usable for the future if the site ever needed maintenance. All-in-all, simple and useful.
How to setup a custom maintenance page
This is totally cribbed from the capistrano default task for deploy:web:disable. My only change is the location of the maintenance template.
In config/deploy.rb:
namespace :deploy do namespace :web do desc "Put the `we're working on it' message up using config/templates/maintenance.html.erb" task :disable, :roles => :web, :except => { :no_release => true } do require 'erb' on_rollback { run "rm #{shared_path}/system/maintenance.html" } template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.html.erb")) result = ERB.new(template).result(binding) put result, "#{shared_path}/system/maintenance.html", :mode => 0644 end end end
Simple how-to-include twitter
The interesting twist is putting—instead of stock ,”Coming soon,” or, “We’ll be right back”—a twitter message right into the maintenance page. The last tweet from the account for the site is automatically included.
The javascript, which doesn’t depend on any outside libraries, for updating a portion of the page with the most recent tweet:
<head> <script type="text/javascript"> function tweetCallback(data) { var tweet = data[0]; if (text = tweet["text"]) document.getElementById('tweet').innerHTML = ' : ' + text; } </script> </head>
At the bottom of the maintenance.html.erb body:
<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/TWITTER_USERNAME_HERE.json?callback=tweetCallback&count=1"></script>
Why its a good idea
I’m really happy with including the last twitter message for the text. Firstly, the client can change the page whenever they want without contacting me. Also, it doesn’t involve any application code, which is important since this is also the page the user will see when the site is down. It promotes the twitter account for the site and at the same time is a totally sensible place to update any possible status messages should they arise.





