Rails 3 Atom Feed
Posted
by
scud bomb
on Stack Overflow
See other posts from Stack Overflow
or by scud bomb
Published on 2012-03-27T23:32:30Z
Indexed on
2012/05/31
22:40 UTC
Read the original article
Hit count: 251
Trying to create an atom feed in Rails 3. When i refresh my browser i see basic XML, not the Atom feed im looking for.
class PostsController < ApplicationController
# GET /posts
# GET /posts.xml
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
format.atom
end
end
index.atom.builder
atom_feed do |feed|
feed.title "twoconsortium feed"
@posts.each do |post|
feed.entry(post) do |entry|
entry.title post.title
entry.content post.text
end
end
end
localhost:3000/posts.atom looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
<id>tag:localhost,2005:/posts</id>
<link rel="alternate" type="text/html" href="http://localhost:3000"/>
<link rel="self" type="application/atom+xml" href="http://localhost:3000/posts.atom"/>
<title>my feed</title>
<entry>
<id>tag:localhost,2005:Post/1</id>
<published>2012-03-27T18:26:13Z</published>
<updated>2012-03-27T18:26:13Z</updated>
<link rel="alternate" type="text/html" href="http://localhost:3000/posts/1"/>
<title>First post</title>
<content>good stuff</content>
</entry>
<entry>
<id>tag:localhost,2005:Post/2</id>
<published>2012-03-27T19:51:18Z</published>
<updated>2012-03-27T19:51:18Z</updated>
<link rel="alternate" type="text/html" href="http://localhost:3000/posts/2"/>
<title>Second post</title>
<content>its that second post type stuff</content>
</entry>
</feed>
© Stack Overflow or respective owner