尝试在Rails3中创建Atom提要。当我刷新浏览器时,我看到的是基本的XML,而不是我正在寻找的Atom提要。
class PostsController < ApplicationController
  # GET /posts
  # GET /posts.xml
  def index
    @posts = Post.all
    respond_to do |format|
      format.html # index.html.erb
      format.xml { render :xml => @posts }
      format.atom
    end
  endindex.atom.builder
atom_feed do |feed|
  feed.title "twoconsortium feed"
  @posts.each do |post|
    feed.entry(post) do |entry|
      entry.title post.title
      entry.content post.text
    end
  end
endlocalhost:3000/posts.atom如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:localhost,2005:/posts</id>
  <link rel="alternate" type="text/html" href="http://localhost:3000"/>
  <link rel="self" type="application/atom+xml" href="http://localhost:3000/posts.atom"/>
  <title>my feed</title>
  <entry>
    <id>tag:localhost,2005:Post/1</id>
    <published>2012-03-27T18:26:13Z</published>
    <updated>2012-03-27T18:26:13Z</updated>
    <link rel="alternate" type="text/html" href="http://localhost:3000/posts/1"/>
    <title>First post</title>
    <content>good stuff</content>
  </entry>
  <entry>
    <id>tag:localhost,2005:Post/2</id>
    <published>2012-03-27T19:51:18Z</published>
    <updated>2012-03-27T19:51:18Z</updated>
    <link rel="alternate" type="text/html" href="http://localhost:3000/posts/2"/>
    <title>Second post</title>
    <content>its that second post type stuff</content>
  </entry>
</feed>发布于 2012-06-01 06:13:50
我遇到了同样的问题。
Atom
headers调用中直接覆盖来自format散列的响应头。只需添加一个具有典型Atom mime类型字符串的代码块:respond_to do |format|
  format.html # index.html.erb
  format.xml { render :xml => @posts }
  format.atom { headers["Content-Type"] = 'application/atom+xml; charset=utf-8'}
end发布于 2012-03-28 08:27:22
This可能有助于在XHTML中格式化提要。
https://stackoverflow.com/questions/9899182
复制相似问题