Search code examples
model-view-controllerruby-on-rails-3google-apigoogle-docs-api

Ruby On Rails XML to View


I have a controller with an API request showing all my Google Docs.

feed = client.get('http://docs.google.com/feeds/documents/private/full').to_xml

    feed.elements.each('entry') do |entry|
      puts 'title: ' + entry.elements['title'].text
      puts 'type: ' + entry.elements['category'].attribute('label').value
      puts 'updated: ' + entry.elements['updated'].text
      puts 'id: ' + entry.elements['id'].text

      # Extract the href value from each <atom:link>
      links = {}
      entry.elements.each('link') do |link|
        links[link.attribute('rel').value] = link.attribute('href').value
      end
      puts links.to_s

end

So, I can see the results in my console but how do I get them into my view?

I tried with something like this, but that doesn't work (I changed my variable in the controller to an accessor of course)

<% feed.elements.each('entry') do |entry| %> <% entry.elements['title'].text %> <% end %>


Solution

  • Problem solved. Because I use 'puts' in the controller to show the content of the feed in the console I also have to change that for the view. Of course, puts is equal to <%= ... %>.

    <ul>
        <% @feed.elements.each('entry') do |entry| %>
            <li><%= 'title: ' + entry.elements['title'].text %></li>
        <% end %>
    </ul>