Last deployment date with Rails and Capistrano

When you are developing an app or a website for your client, it is pretty common to setup a sandbox environment where your client can test and see the application while it is still in development. One thing I find useful is to display the last deployment date on the home page.

Here is a quick and easy way to automate the process :

Step #1 (we can have lots of fun)
I will consider that you use capistrano for deploying your app. The only thing you have to do in your capistrano recipe is to “touch” a dummy file to update its modification date.

Step #2 (there’s so much we can do)
Now in application_controller, add a before_filter like this

Step #3 (it’s just you and me)
Display the date in the layout or in the view of your choice

Edit : Oh, dear readers, I just want to let you know that RubyFleebie is now on Twitter.

  • Ian Neubert

    I think you could also use the REVISION file that capistrano places by default during a deploy. You could also get the SVN/git revision from this file by reading it.

    Thanks for the tip!

  • Josh Nesbitt

    You could also pull the timestamp from the most recent folder within the releases directory, as Capistrano uses timestamped folder names as a way of separating revisions of code over different deploys. Nice idea :)

  • Frank

    Thanks guys for these nice alternatives!

  • Pingback: Last deployment date with Rails and Capistrano()

  • Bastian Kruck

    When using passenger, why not check for the last change on tmp/restart.tmp?

    File.atime(“#{Rails.root}/tmp/restart.txt”).strftime(“%Y-%m-%d at %H:%M”)

    will work with just this single line :)

  • Frank

    Bastian, that”s a good idea! Even simpler for passenger users

  • Josh Nesbitt

    I’m not sure the last access time would suffice. What if you you needed to restart the application but haven’t deployed new code in-between restarts?

  • Frank

    Josh, agreed. restart.txt is a bit less reliable than a custom dummy file for the reason you mention.