3
votes

I'm trying to iterate over each articles' pictures in an Atom feed. I have the following code which renders an Atom feed just fine, but am not sure if these are the correct image tags.

Any advice on what the optimal setup for this is would be amazing.

This renders the XML below; 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 output:

<?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>
1
Did you ever solve this? - stephenmurdoch
Hi Stephen, we did solve it however we too a different approach to putting the image in an atom feed. As our feed was being imported into google currents and currents automatically puts any images included like the method below into a slideshow (which we didnt want) we decided to just include the img tag of the image in the body content of our article/post or whatever. Not really a solution but it worked better for our needs. - dodgerogers747
Thanks, that makes sense, it's what I'm doing now too. - stephenmurdoch

1 Answers

1
votes

Could be wrong, but you might just need an html_safe call on it.

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