1

我似乎无法正确地为博客文章添加类别的语法。

index.atom.builder

atom_feed language: 'en-US', schema_date: 2013 do |feed|
  feed.title @title
  feed.updated @updated

  @posts.each do |post|
    next if post.updated_at.blank?
    feed.entry post, published: post.published_at do |entry|
      entry.title post.title
      entry.summary post.summary.blank? ? truncate("#{strip_tags(post.content)}", length: 140, separator: ' ') : strip_tags(post.summary)
      entry.content post.content, type: 'html'
      entry.author do |author|
        author.name post.user ? post.user.name : post.author
      end
      post.categories.map {|c| c.name}.each do |t|
        entry.category term: t, label: t, scheme: 'http://mywebsite.com'
      end
    end # end feed.entry
  end # end @posts.each
end

回答了我自己的所有问题。对于遇到此问题的任何人,这将为您提供经过验证的 atom 提要!仅当您不想使用默认值和值时,才需要published:在块中传递值。在http://validator.w3.org/feed/检查您的提要以检查您的提要!|entry|created_atupdated_at

4

1 回答 1

1

这就是我最终使用的。这实际上将 2 个不同的模型放入提要中。

视图/条目/feed.atom.builder

atom_feed language: 'en-US', schema_date: 2013 do |feed|
  feed.title @title
  feed.updated @updated

  @entries.each do |e|
    next if e.updated_at.blank?
    feed.entry e do |entry|
      entry.title e.name
      entry.summary e.summary.blank? ? truncate("#{strip_tags(e.content)}", length: 140, separator: ' ') : strip_tags(e.summary), type: 'html'
      entry.content e.content, type: 'html'
      entry.author do |author|
        author.name e.user.name
      end
      e.categories.map {|c| c.name}.each do |t|
        entry.category term: t, label: t, scheme: root_url
      end
      entry.category term: 'blog', label: 'blog', scheme: root_url
    end # end feed.entry
  end # end @entries.each

  @designs.each do |d|
    next if d.updated_at.blank?
    feed.entry d do |entry|
      entry.title d.name
      entry.summary truncate("#{strip_tags(d.content)}", length: 140, separator: ' '), type: 'html'
      entry.content d.content, type: 'html'
      entry.author do |author|
        author.name User.first.name
      end
      d.categories.map {|c| c.name}.each do |t|
        entry.category term: t, label: t, scheme: root_url
      end
      entry.category term: 'design', label: 'design', scheme: root_url
    end # end feed.entry
  end # end @designs.each
end
于 2013-12-11T19:03:13.323 回答