Add Feed Discovery Links Easily

I’m working on discussion forums for NearbyGamers and I’m building the first feeds into the site. I worked up a clean way to add them from my controllers similar to my tidy stylesheets code. Here’s how to do it.

In the <head> of your app/views/layouts/application.rhtml call the auto_discovery_link_tag to print the tags:

` <%- @feeds.each do feed -%> <%= auto_discovery_link_tag(:atom, *feed) %> <%- end -%> `{lang=”ruby”}

In app/controllers/application.rb:

def initialize @feeds = [] end

def add_feed title, options={} @feeds << [ { :controller => self.controller_name, :action => self.action_name, :format => ‘atom’ }.update(options), { :title => title } ] end

And you’re all set up. Where you want an action to present feeds, call add_feed. After title, it takes options for url construction.

` add_feed ‘New discussions’ add_feed ‘New posts’, :action => ‘posts’, :sort_by => ‘new’ `{lang=”ruby”}

It defaults to the current action with a format of ‘atom’ so you can add feed code to your respond_to block. I’ll post again soon with code integrate resource_feeder to do this.