Hi friends,
We have recently talked about auto_discovery_link_tag, that consumes RSS and Atom feeds. Now we are going into deep what is the atom feeds in Rails and how we can achieve that. Lets begin with a defining Atom Feeds.
Atom Feeds are XML -based file format used to syndicate content.It was designed to be a universal publishing standard for blogs and other Web sites where content is updated frequently. Atom feeds can be used by users in feed readers to browse content or by search engines to help discover additional information about your site.
In rails atom feeds can be easily built using a helper atom_feed. How to use it can be well understood through an example. Suppose your site have blogs, that are created and updated frequently and you want these be reflected in atom feed. You can achieve this as:
Lets your route file has resource blogs, then blogs controller index would be like this:
def index
@blogs = Blog.all
respond_to do |format|
format.html
format.atom
end
end
Now to show atom feed, you need to create a index.atom.builder under app/views/blogs:
atom_feed do |blog|
blog.title("Blogs Index")
blog.updated((@blogs.first.created_at))
@blogs.each do |blog|
blog.entry(blog) do |entry|
entry.title(blog.title)
entry.content(blog.description, type: 'html')
entry.author do |creator|
author.name(blog.creator_name)
end
end
end
end
Hope you liked this blog. For more Click here
0 Comment(s)