Hi! I'm Nathan Hoad


Easy RFC822 Datetimes for RSS in Rails

If you are generating an RSS feed in your Rails app you might be doing something like this for datetimes (eg. pubDate):

item.updated_at.strftime("%a, %d %b %Y %H:%M:%S %z")

There is a much simpler way. Datetimes in Rails have an rfc2882 method that gives us the right format automatically:

item.updated_at.rfc2822

This way is a lot cleaner and easier to read.

If I just made your day a little better then thank me with a coffee or maybe a a pizza