Posts tagged with “FeedBurner”
- All (1)
- Entries (1)
- Links (0)
- Photos (0)
RESTfully Forward Users to FeedBurner in Rails
After launching my new site, I realized I had forgotten to use FeedBurner to track my RSS feed subscribers. Because FeedBurner requires that you forward users to your feed on their servers, I needed a way to forward users along, but I also wanted to make sure that if FeedBurner’s spider came to the same feed URL, they would be served the source RSS instead of being forwarded. My solution ended up like this:
class NotebooksController < ApplicationController
def show
respond_to do |format|
format.html
format.rss do
unless request.env['HTTP_USER_AGENT'] =~ /feedburner/i
redirect_to 'http://feeds.feedburner.com/KyleSlattery'
end
end
end
end
end
If you take a close look at the, all I’m doing is checking the user agent of the request, and unless it’s FeedBurner, I redirect the user to the “burned” feed. If it is FeedBurner, things go ahead normally, and the RSS feed gets rendered.
This means that instead of creating separate actions, one that forwards to FeedBurner, and one that renders the RSS, I just have one action/URL that does both: http://kyleslattery.com/notebook.rss. So far, it’s worked great, and doing it this way really helped to keep my code clean and RESTful.
