Rails 3 RSS feed帮助xml解析错误

时间:2011-04-26 19:12:28

标签: ruby-on-rails ruby ruby-on-rails-3

我在视图中看到了这个xml错误:

XML parse error: no element found
Location: http://localhost:3000/feed
Line 1, column 2:

我的路线.rb

match '/feed' => 'konkurrancers#feed',
      :as => :feed,
      :defaults => { :format => 'xml' }

我的控制器:

def feed
@posts = Konkurrancer.all(:select => "name, tracking, id, created_at", :order => "created_at DESC", :limit => 20)
    respond_to do |format|
      format.html
      format.rss { render :layout => false } #index.rss.builder
    end

我的index.rss.builder:

xml.instruct! :xml, :version => "1.0" 
xml.rss :version => "2.0" do
  xml.channel do
    xml.title "Your Blog Title"
    xml.description "A blog about software and chocolate"

    for konkurrancer in @posts
      xml.item do
        xml.title konkurrancer.name
        xml.pubDate konkurrancer.posted_at.to_s(:rfc822)
        xml.link konkurrancer.tracking
        xml.guid konkurrancer.tracking
      end
    end
  end
end

end

1 个答案:

答案 0 :(得分:0)

不是xml,而是rss

match '/feed' => 'konkurrancers#feed',
      :as => :feed,
      :defaults => { :format => 'rss' }