代码之家  ›  专栏  ›  技术社区  ›  Nick

rails atomfeedbuilder条目:url选项出现在url标记中,但不出现在link标记中

  •  8
  • Nick  · 技术社区  · 15 年前

    我正在使用atomfeedhelper,除了一个feed,我需要将每个条目链接到一个url,这个url不是记录的默认多态url之外,其他一切都正常工作。

    根据文档,我为条目指定了一个:url选项。这将正确地呈现 <url> 在atom节点中标记 <link rel="alternate" 仍然指向默认的多态URL。看看源代码和文档,我不明白为什么会这样。

    下面是一个示例生成器:

    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
    

    下面是一个问题节点的示例:

     <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>
    

    我希望链接标记中的Href值与URL标记中的值匹配,但它不匹配。

    当我查看此处列出的输入源时 http://api.rubyonrails.org/classes/ActionView/Helpers/AtomFeedHelper/AtomFeedBuilder.html

    我假设这条线能正常工作:

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

    困惑的。以前有人遇到过吗?

    谢谢大家!

    1 回复  |  直到 8 年前
        1
  •  18
  •   Chris Conley    14 年前

    我通过将:url选项直接传递给feed.entry方法来实现这一点:

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

    推荐文章