简体   繁体   English

如何在Rails 3中创建原子提要?

[英]How to create an atom feed in Rails 3?

I'm trying to set up a simple atom feed from my Posts model and I'm running into translation problems between rails 2 and rails 3. 我正试图从我的Posts模型中设置一个简单的原子进给,我遇到了rails 2和rails 3之间的转换问题。

I tried to accomplish this task with two steps: 我尝试通过两个步骤完成此任务:

Added the <%= auto_discovery_link_tag(:atom) %> to my /views/layouts/application.html.erb file. 在我的/views/layouts/application.html.erb文件中添加了<%= auto_discovery_link_tag(:atom) %>

Created a /views/posts/index.atom.builder file. 创建了/views/posts/index.atom.builder文件。 The file contains: 该文件包含:

atom_feed do |feed|   
  feed.title("Daily Deal")   
  feed.updated(@posts.first.created_at)
  @posts.each do |post|
    feed.entry(post) do |entry|
      entry.title(post.title)
      entry.content(post.body, :type => 'html')
      entry.author { |author| author.name("Justin Zollars")}
    end
  end
end

I see the RSS link in my browser, but the link opens with an error: 我在浏览器中看到了RSS链接,但链接打开时出现错误:

  Too many redirects occurred trying to open
  “feed:http://localhost:3000/posts”.
  This might occur if you open a page
  that is redirected to open another
  page which then is redirected to open
  the original page.

Where have I gone wrong? 我哪里出错了?

尝试指定Feed的路径:

<%= auto_discovery_link_tag(:atom, posts_path(:atom)) %>

Maybe you need to specify the actual feed address? 也许您需要指定实际的Feed地址?

auto_discovery_link_tag :atom, "http://mysite.com/posts.atom"

If you're using FeedBurner, you'll want to use that address instead. 如果您使用的是FeedBurner,则需要使用该地址。

Also, do you have some kind of before_filter blocking the access to that page? 此外,您是否有某种before_filter阻止访问该页面?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM