3

我正在尝试遍历 Atom 提要中每篇文章的图片。我有以下代码可以很好地呈现 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>
4

1 回答 1

1

可能是错的,但你可能只需要一个html_safe电话就可以了。

 entry.logo image_tag(pic.photo.url(:large)).html_safe
于 2012-09-10T19:54:16.227 回答