我想创建一个简单的RSS / Atom提要。
Feed应列出最多20个konkurrancer。
每个konkurrancer的标题应该是konkurrancer.name
rss feed链接应该是konkurrancer.tracking,这是一个url
这是我的建设者:
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
我在视图中收到此错误:
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'
我的模特:
class Konkurrancer < ActiveRecord::Base
validates_presence_of :name, :tracking, :banner1, :banner2, :kategori_id, :udtraekkes, :tid, :vaerdi,
end
答案 0 :(得分:0)
您应该将对象传递给entry
方法:
http://apidock.com/rails/ActionView/Helpers/AtomFeedHelper/AtomFeedBuilder/entry
entry(record, options = {}) public
例如 feed.entry(konkurrancer)
答案 1 :(得分:0)
fl00r有正确指向您问题的指针。一个基本的例子:
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
我最近发布了这个帖子,请在此处查看完整的操作方法(带代码):http://www.communityguides.eu/articles/14