Rails 3 help building simple RSS feed
I want to create an simple RSS/Atom feed.
The feed should list max 20 konkurrancer.
The title of each konkurrancer should be konkurrancer.name
The rss feed link should be konk开发者_运维技巧urrancer.tracking which is a url
This is my builder:
atom_feed :language => 'en-US' do |feed|
feed.title @title
feed.updated @updated
@news_items.each do |item|
next if item.updated_at.blank?
for konkurrancer in @news_items
feed.entry do |entry|
entry.tracking
entry.title item.title
entry.content item.content, :type => 'html'
# the strftime is needed to work with Google Reader.
entry.updated(item.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ"))
end
end
end
end
I get this error in view:
ArgumentError in Konkurrancers#feed
Showing C:/Rails/konkurranceportalen/app/views/konkurrancers/feed.atom.builder where line #9 raised:
wrong number of arguments (0 for 1)
Extracted source (around line #9):
6: next if item.updated_at.blank?
7: for konkurrancer in @news_items
8:
9: feed.entry do |entry|
10: entry.tracking
11: entry.title item.title
12: entry.content item.content, :type => 'html'
My model:
class Konkurrancer < ActiveRecord::Base
validates_presence_of :name, :tracking, :banner1, :banner2, :kategori_id, :udtraekkes, :tid, :vaerdi,
end
you should pass an object to your entry
method:
http://apidock.com/rails/ActionView/Helpers/AtomFeedHelper/AtomFeedBuilder/entry
entry(record, options = {}) public
feed.entry(konkurrancer)
for example
fl00r had the correct pointer to your problem. A basic example:
atom_feed do |feed|
feed.title "Title"
feed.updated @articles.first.created_at
@articles.each do |article|
feed.entry article do |entry|
entry.title article.titl
entry.content article.body, :type => 'html'
entry.author do |author|
author.name article.author
end
end
end
end
I posted about this recently, see the full how-to (with code) here: http://www.communityguides.eu/articles/14
精彩评论