How to make an RSS feed in Rails
2010-02-12 22:12:05 +0000
Easy. Don’t. Use an ATOM feed instead. Rails is opinionated software, it has an opinion on feeds, there is an atom_feed helper, but no rss_feed helper? Omission? Nup.
I added the ATOM feed to Rails Plugins website very simply, by using the Rails atom_feed helper. It was a simple case of creating a FeedsController with just a single index action, which collected up all the time line events that needed to go onto the feed and assigned them to the view in an @events ivar.
So the controller looks like this:
class FeedsController < ApplicationController
layout false
def index
@events = TimelineEvent.for_feed
@title = "Rails Plugins Feed"
@updated = @events.first.created_at unless @events.empty?
end
end
Then in the view file app/views/feeds/index.atom.builder looks like this:
atom_feed do |feed|
feed.title(@title)
feed.updated(@updated)
@events.each do |event|
feed.entry(event) do |entry|
entry.title(h(event.title))
entry.summary(truncate(strip_tags(event.description), :length => 100))
entry.author do |author|
author.name(event.author_name)
end
end
end
end
And then the route to wire it up:
# config/routes.rb (Rails 2.0) ActionController::Routing::Routes.draw do |map| map :resources :feeds, :only => [:index] end
And finally the auto_discovery_link_tag in the application.html.erb:
<%= auto_discovery_link_tag(:atom, "/feeds.atom") %>
Now this was all well and good, and I thought, why not add an RSS feed as well?
I started down on this path and the first thing that struck me was, there was no rss_feed helper in Rails, why? Seemed like an ommission…
Then I was looking around the web and found many examples on how to do an RSS feed in Rails, but none of them mentioned this omission of the helper, why?
I didn’t puzzle over this long, and just went ahead and added an RSS feed, it wasn’t hard, you can find this out from your friend google.
But then I got this IM from Sam Ruby after I let him know the RSS feed for Rails Plugins was now online:
“Ewwwww”
Which was not really the answer I was expecting, so I stated:
“I never did get the ATOM v RSS debate”
To which he replied:
“I started the Atom vs RSS debate.”
And that started an interesting chat! Let me tell you!
Turns out that ATOM is actually defined, with RFC 4287 that covers all the basics of what you need to know.
Also turns out that any modern reader will handle ATOM, just as easily as RSS.
Also turns out that with ATOM you can define things like (gasp) language settings, Internationalization, content types and several other points which make the data a lot more consumable.
So, then I added the following to the Rails Plugins website:
class FeedsController < ApplicationController
def index
# ...
respond_to do |wants|
wants.rss do
redirect_to feeds_path(:format => :atom),
:status=>:moved_permanently
end
wants.atom
end
end
end
And decided to sum up my gained knowledge with: We are Rails, we are opinionated, ta-ta RSS http://bit.ly/c9eyNL – KTHXBAI
blogLater
Mikel




2012-08-06 05:40:10 +0000
Positive site, where did u come up with the information on this posting? I’m pleased I discovered it though, ill be checking back soon to find out what additional posts you include.
Sports News Australia
2012-08-06 05:43:18 +0000
Positive site, where did u come up with the information on this posting? I’m pleased I discovered it though, ill be checking back soon to find out what additional posts you include.
Sports News Australia
2012-08-06 05:43:29 +0000
Positive site, where did u come up with the information on this posting? I’m pleased I discovered it though, ill be checking back soon to find out what additional posts you include.
Sports News Australia
2012-09-08 04:43:00 +0000
i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future..
Galoor
2010-02-12 22:30:17 +0000
Pz, bitches (RSS)!!!!
Love it when devs push back against shitty technologies.
2010-02-14 10:22:39 +0000
Nothing wrong with being a little opinionated right?
2010-02-13 04:55:50 +0000
Speaking of feeds, could I ask you to provide a full-text feed for your blog entries?
2010-02-21 06:37:56 +0000
Can I second the call for a full-text feed? Excerpts just add to the time it takes to get through my feeds.
(It’s not as if this is an ad-heavy site that needs to use this technique to force people to see the ads, after all…)
2010-02-21 15:08:24 +0000
@tiny and @pawel
Done. Full text feeds are now in place :)
Mikel
2010-02-24 22:10:16 +0000
www.DrinkRails.com Linked your post
2010-03-01 11:51:24 +0000
Great post. Recently I had to do the same thing and decided to go just with an ATOM feed.
Just one thing, in your index action you have the following code:
def index
@events = TimelineEvent.for_feed
@title = “Rails Plugins Feed”
@updated = @events.first.created_at unless @events.empty?
end
But, inside the RFC we have:
“The “atom:updated” element is a Date construct indicating the most recent instant in time when an entry or feed was modified in a way the publisher considers significant. Therefore, not all modifications necessarily result in a changed atom:updated value."
So, instead of:
@updated = @events.first.created_at unless
I’m doing:
@updated = @events.last.created_at unless @events.empty?
What do you think about it?
2011-11-08 19:55:20 +0000
Can I second the call for a full-text feed? Excerpts just add to the time it takes to get through my feeds.
2010-08-05 11:28:19 +0000
Thanks so much! After giving up on the idea of running Wordpress on a subdomain, I gave in to rolling my own blog. This helped so much!
2010-11-26 06:32:53 +0000
I’m using pretty urls for the articles such mysite.com/en/articles/2010/11/26/title-of-the-article and I have an helper method for getting the url of the article.
To override the article url you need to specify it as an entry :url option like:
feed.entry(article, :url => get_article_url(article)) do |entry|
2010-12-13 21:41:51 +0000
Nice post, will this work on Rails 3? I’ve been curious about adding rss to my site.
2011-06-14 01:22:26 +0000
Sometimes, though, your customer is just adamant, and you’ve written all the atom_feed parts but they REALLY want RSS.
So I was forced to write this: http://www.zephyros-systems.co.uk/blog/?p=179
2012-09-02 22:58:56 +0000
I realy like this article. This is a hash of default values for any email you send, in this case we are setting from the header to a value for all messages in this class, this can be overridden on a per email basis..
Mesin Kasir | Komputer Kasir | Jual Barcode | Printer Kasir
Printer Kartu
2012-09-02 23:01:02 +0000
Nice Article, I feel strongly that love and read more on this topic. it’s very spectaculer.
Mesin Kasir | Komputer Kasir | Jual Barcode | Printer Kasir
Printer Kartu
2012-03-24 07:40:02 +0000
Finally I understand how to do it. Thanks!
2012-06-05 01:40:08 +0000
Going for ATOM instead of RSS. Thanks for sharing !!
2012-06-05 01:40:26 +0000
Going for ATOM instead of RSS. Thanks for sharing !!
2012-06-05 01:44:53 +0000
Mikel, something weird is going on with the comments. They are not ordered by date. I’m sorry I submitted my last comment twice.
2012-04-03 07:06:25 +0000
I would like to say that this blog really convinced me to do it! Thanks, very good post.
2012-04-04 08:48:53 +0000
Very nice article, I enjoyed reading your post, very nice share, I want to twit this to my followers. Thanks! gluten free
2012-04-25 07:45:00 +0000
I have read your blog it is very helpful for me. I want to say thanks to you. I have bookmark your site for future updates.
new horoscope signs
2012-08-01 02:43:28 +0000
Great post, I always follow your blog since it is full of persuasive information about various things
2012-08-01 05:08:38 +0000
Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it’s nice to find a website that details so much information about different artists.
Paphos hotels
2012-09-29 07:56:31 +0000
Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
http://fr.onlinebaccara.com
2012-10-13 07:15:02 +0000
Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..
http://www.point-box.com
2012-12-18 08:16:54 +0000
I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post.
cheap adjustable dumbbells
2013-01-03 13:18:13 +0000
I have to say this post was certainly informative and contains useful content for enthusiastic visitors.
Zimmet Vein & Dermatology-Austin
2013-01-04 09:40:40 +0000
The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.PS3 Emulator
2013-01-19 09:58:50 +0000
Upon seeing those families having a trail, I envy because I never got a chance to have to. However, I am still happy that the parents are spending much of their time for the kids.Xbox Emulator
2013-04-15 23:41:03 +0000
Children’s tooth development begins while the baby is in the womb. Teething usually occurs between the ages of six and nine months. Children usually have their full set of 20 primary teeth (milk teeth, baby teeth or deciduous teeth) by the age of three years. At about the age of six years, the first permanent teeth erupt (push through the gum).
2013-04-24 21:47:00 +0000
Seriously worthwhile write-up. Spend interest string http://gotenerife-plus.com/hydrofory.xhtml
2013-05-02 19:59:48 +0000
I seriously get pleasure from your posts. Many thanks drukarki bielsko biała http://taiyche.org.pl/?p=6065
2013-05-09 09:42:07 +0000
Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it’s nice to find a website that details so much information about different artists.
e cigarette reviews
2013-05-18 16:00:56 +0000
Today’s houses are larger and more costly than ever. They load our sensible resources. After they are built they place an ever-growing trouble on our pocketbooks and forcefulness resources, because they are not built in an environmentally awake way.
http://foro.spainlanuit.com/viewtopic.php?f=28&t=49143&p=89816
http://delustu.org.pl/?p=5931
http://www.jurekband.pl/pokaz.php?id=209
http://www.linkworld.pl/firmy/hotel,opera,konferencje,w,sopocie,s,10038/
http://www.jurekband.pl/pokaz.php?id=160
http://kimanildcerdra.com.pl/?p=5680
http://stripercup.com/viewtopic.php?f=12&t=15997
http://rilim-ack.edu.pl/?p=5551
http://www.metalfan.ro/forum/viewtopic.php?f=4&t=109032&start=0
http://www.zielonykatalog.net.pl/firmy/hotel,opera,szkolenie,w,sopocie,s,3142/
2013-05-22 01:52:08 +0000
I am curious to find out what blog platform you have been working with? I’m having some small security problems with my latest blog and I’d like to find something more safeguarded. Do you have any recommendations? osiowanie maszyn http://urzadzenialakierniczemarius.pl/wywazanie-wirnikow/