2012-09-10 49 views
3

我正在嘗試遍歷Atom提要中的每篇文章的圖片。我有以下代碼呈現Atom提要很好,但不知道這些是否是正確的圖片標籤。使用Rails在Atom feed中顯示圖像?

任何有關最佳設置的建議都會很棒。

這呈現下面的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

你有沒有解決這個問題? – stephenmurdoch

+1

嗨斯蒂芬,我們確實解決了它,但我們也有一種不同的方法將圖像放在原子進給中。由於我們的Feed正在導入谷歌電流和電流中,因此會自動將以下方法中包含的任何圖像放入幻燈片中(我們不想要),因此我們決定在圖像/文章的正文內容中僅包含圖像的img標籤或隨你。不是一個真正的解決方案,但它對我們的需求更好。 – dodgerogers747

+0

謝謝,這很有道理,這也是我現在正在做的。 – stephenmurdoch

回答

1

可能是錯的,但你可能只需要在其上的html_safe電話。

entry.logo image_tag(pic.photo.url(:large)).html_safe 
+0

嗯,仍然似乎沒有工作,其原子非常具體的圖像以2:1的比例?如果他們不是這種格式,他們不會顯示? – dodgerogers747

+0

或多或少地注意到圖像標籤如何通過轉義的html標籤進行渲染。就原子規格而言,我真的不知道,對不起。 – agmcleod