Saturday, July 15, 2006

Generate RSS Feed


Neha Gupta
has submitted this Ruby code snippet:
xml.rss(:class => "Recipe", :version => "x.x", :xmlns
=> "www.codewalla.com") do
xml.channel do
@Recipes = Recipe.find_all
xml.title("List of Recipes -- Total ", Recipe.count,
" recipes")
xml.link
xml.description
xml.RecipesAuthor("CodeWalla")
@Recipes.each do |item|
xml.item do
xml.Title(item.title)
xml.link
xml.author("CodeWalla")
xml.desciption(item.description)
xml.date(item.date)
xml.category(item.category.name)
end
end
end
end
The above code is made to generate a rss feed of a particular table from a database. Here, Recipe is a table name and item is the variable in m used to store one recipe temporarily, to display its contents. This code needs to be stored in .rxml file.
Eg: D:/Copy of rails/cookbook/app/views/actor/index.rxml

It can be invoked by:
http://localhost:3000/actor/index.rxml

The output of the code is:
<rss xmlns="www.codewalla.com" version="x.x" class="Recipe">
<channel>
<title>List of Recipes -- Total 4 recipes</title>
<link/>
<description/>
<RecipesAuthor>CodeWalla</RecipesAuthor>
<item>
<Title>codewal;l</Title>
<link/>
<author>CodeWalla</author>
<desciption></desciption>
<date></date>
<category>Dessert</category>
</item>
<item>
<Title>bbbbbbbbbbbbbb</Title>
<link/>
<author>CodeWalla</author>
<desciption>bbbbbbbbbbbbbb</desciption>
<date>2006-05-04</date>
<category>Starters</category>
</item>
<item>
<Title>dsfhsjdflk</Title>
<link/>
<author>CodeWalla</author>
<desciption>;kkb;k</desciption>
<date>2006-05-04</date>
<category>Starters</category>
</item>
<item>
<Title>Ice Tea</Title>
<link/>
<author>CodeWalla</author>
<desciption>Good !!!</desciption>
<date>2006-05-04</date>
<category>Dessert</category>
</item>
</channel>
</rss>
Kindly comment on this code.
Technorati Tags:
Blogs linking to this article

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home