Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails AtomFeedBuilder Entry :Url option appears in url tag but not in link tag

I'm using the AtomFeedHelper and everything is working fine except for one feed where I need to link each entry to a URL which is not the default polymorphic_url for the record.

Per the documentation I've specified an :url option for the entry. This correctly renders a <url> tag in the atom node but the <link rel="alternate" still points to the default polymorphic_url. Looking at the source and the documentation I don't understand why this is happening.

Here's an example builder:

atom_feed do |feed|
  feed.title("Reports")
  feed.updated(@reports.first.created_at)
  for report in @reports
    content = report.notes

    feed.entry(report) do |entry|
      entry.title(report.title)
      entry.content(content, :type => 'html')
      entry.url("http://myhost/page/")
      entry.updated(report.updated_at.strftime("%Y-%m-%dT%H:%M:%SZ"))
      entry.author do |author|
        author.name(report.user.username)
      end
    end
  end

end

Here's an example of a problem node:

 <entry>
    <id>tag:myhost.mydomain.com,2005:SiteReport/2</id>
    <published>2010-03-30T13:11:07-07:00</published>
    <updated>2010-03-30T13:11:07-07:00</updated>
    <link rel="alternate" type="text/html" href="http://myhost/site_reports/2"/>
    <title>Test Title</title>
    <content type="html">Test Content</content>
    <url>http://myhost/page/</url>
    <updated>2010-03-30T13:11:07Z</updated>
    <author>
      <name>Author</name>
    </author>
  </entry>

I want the href value in the link tag to match the value in the url tag but it does not.

When I look at the source listed for entry here http://api.rubyonrails.org/classes/ActionView/Helpers/AtomFeedHelper/AtomFeedBuilder.html

I'd assume that this line would work correctly:

 @xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:url] || @view.polymorphic_url(record))

Confused. Has anyone encountered this before?

Thanks all!

like image 552
Nick Avatar asked Apr 01 '10 15:04

Nick


1 Answers

I accomplished this by passing the :url option directly to the feed.entry method:

feed.entry(report, :url => report_url(report.slug)) do |entry|

like image 51
Chris Conley Avatar answered Nov 18 '22 21:11

Chris Conley