当我在浏览器中访问myapp/feed时,我得到这个错误:
NoMethodError in Konkurrancers#feed
Showing C:/Rails/konkurranceportalen/app/views/konkurrancers/feed.atom.builder where line #1 raised:
undefined method `atom_feed' for #<#<Class:0x595dee0>:0x5956f08>
Extracted source (around line #1):
1: atom_feed :language => 'en-US' do |feed|
2: feed.title @title
3: feed.updated @updated
我的控制器:
def feed
# this will be the name of the feed displayed on the feed reader
@title = "Vindhimlen nye GRATIS konkurrencer"
# the news items
@news_items = Konkurrancer.order("updated_at desc")
# this will be our Feed's update timestamp
@updated = @news_items.first.updated_at unless @news_items.empty?
respond_to do |format|
format.atom { render :layout => false }
# we want the RSS feed to redirect permanently to the ATOM feed
format.rss { redirect_to feed_path(:format => :atom), :status => :moved_permanently }
end
end
我的路线:
match '/feed' => 'konkurrancers#feed',
:as => :feed,
:defaults => { :format => 'atom' }
我feed.atom.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?
feed.entry( item ) do |entry|
entry.url news_item_url(item)
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
''是错误解释的控制字符。尝试将#coding: UTF-8
添加为第一行(不要忘记#)到feed.atom.builder