使用Rails在Atom feed中显示图像?

时间:2012-09-10 16:45:30

标签: ruby-on-rails ruby atom-feed

我正在尝试在Atom Feed中迭代每篇文章的图片。我有以下代码,使Atom提要很好,但我不确定这些是否是正确的图像标记。

关于最佳设置的任何建议都是惊人的。

这将呈现以下XML; index.atom.builder:

atom_feed do |feed|
  feed.title "posts"
  feed.updated @articles.maximum(:updated_at)

  @articles.each do |article|
    feed.entry(article) do |entry|
      entry.title article.title
      entry.content(article.body, type: 'html')
      entry.author do |author|
        author.name article.author

        if article.pictures.any?
          article.pictures.each do |pic|
            entry.logo image_tag pic.photo.url(:large)
          end
        end 
      end
    end
  end
end

XML输出:

<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:HEROKU APP:/articles</id>
  <link rel="alternate" type="text/html" href="herokuapp.com"/>
  <link rel="self" type="application/atom+xml"herokuapp.com/articles.atom"/>
  <title>posts</title>
  <updated>2012-09-10T16:42:27Z</updated>
  <entry>
    <id>tag:herokuapp.com,2005:Article/9</id>
    <published>2012-09-10T16:42:27Z</published>
    <updated>2012-09-10T16:42:27Z</updated>
    <link rel="alternate" type="text/html" href="herokuapp.com/articles/9-test-lorum"/>
    <title>Test Lorum</title>
    <content type="html">wddsadasdsadasd</content>
    <logo>&lt;img alt="Alaska" src="/assets/articles/12/large/alaska.jpg?1347295345" /&gt;</logo>
    <author>
      <name>Andy</name>
    </author>
  </entry>

0 个答案:

没有答案