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 に答える