For the current application I am working on, I needed the ability to generate RSS feeds on the fly. Users have the ability to search for a lot of different information, and I needed to provide them with a way to save that search via an RSS feed. To see how I went about performing basic search, see here.
In my controller, I started by adding the ability to respond_to rss:
Next, in my routes.rb file, I added a specific route for the dynamic search.
This provided me with the method search_rss_path, which I was able to use in my view. I attempted to use the route that I already had:
With something along the lines of search_path(params, :format => ‘rss’), and that ended up being a very bad thing. This was a bit ago, and I can’t recall at the moment why that wasn’t working, but I do recall that it just ended up being easier and nicer to just add one more route in my routes.rb file.
Continuing on, in my search.html.haml file, I have both a direct link and the auto_discovery link for the search generated RSS:
The content_for :extra header is just an “extra header” area in my application.html.haml file:
Finally, don’t forget to include the search.rss.builder file in your view folder:
All-in-all, it ended up being very easy to implement dynamic, search-based RSS feeds.
Questions? E-mail me: this domain AT gmail DOT com