We’ve had quite a flurry of clients at Resolve Digital (and even ourselves) wanting to integrate their Rails site with a Wordpress blog. We generally recommend our clients use Wordpress if they want a blog but that leads to one problem, Rails is written in Ruby and Wordpress is written in PHP.
And of course the client wants the latest blog post or last few recent posts up on their home page. But that very home page is running off their Rails site, so somehow the Wordpress blog needs to integrate with the Rails site.

How’s how you do it.
Step 1 – Fetch the RSS feed from the Wordpress Blog
Copy this file (rss_parser.rb) into RAILS_ROOT/lib/
This will do the hard work for you. It simply downloads a RSS feed and parses for you.
If that doesn’t float your boat, checkout SimpleRSS as an alternative.
In this example we have PagesController with a home method. Add line 5 to get the latest posts from your blog. Obviously change the RSS feed URL to the one on your Wordpress blog.
Step 2 – Display the post in a view
And finally show the post in the home page view.
I’m sure many of you will prefer to show the latest 3 posts instead, here’s how:
Note you have to run strip_tags() because if you truncate HTML a tag might be open but never close because you snipped the HTML too soon. So we take out all tags first so we just have plain text and then truncate.
Performance
At first I was a little worried that downloading the RSS feed from the blog each time the page is requested would cause performance issues, but for those of us who have sites that don’t have a huge flow of traffic this will do just fine.
If you’re still concerned about it, here’s two ideas:
- Setup a CRON job to download the RSS feed nightly
- Use time based fragment caching to expire that part of the view daily so only the first person to request the page that day triggers the RSS feed to download.

As part of an effort to learn Objective-C, I’ve released my first iPhone app. Admittedly it is very simple, but I’m sure a few of you will have a bit of fun with it.
It isn’t live in the iTunes Store yet, but I’ll post an update when it is. It’s going for US$0.99 (NZ$1.29).
