Rails 3 - 帮助Atom Feed?

时间:2011-05-30 18:16:45

标签: ruby-on-rails-3

感觉就像我一直在四处走动,遵循不同的教程都建议达到承诺的结果,但没有一个能为我工作。我正在使用Kaminari插件,我的文章在索引页面上(6)。任何人都可以帮我这个吗? THX

application.html.rb

auto_discovery_link_tag(:atom) # =>
<link rel="alternate" type="application/atom+xml" title="ATOM" href="http://www.currenthost.com" />

的routes.rb

match '/feed' => 'articles#feed', :as => :feed, :defaults => { :format => 'atom' }

articles_controller.rb

def index
@articles = Article.published.page(params[:page]).per(6).ordered

respond_to do |format|
  format.html # index.html.erb
  format.atom  { @articles = Article.published }
  format.xml  { render :xml => @articles }
end
end

物品/ index.atom.builder

atom_feed do |feed|
feed.title "Title"
feed.updated(@articles.blank? ? Time.now : @articles.first.created_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
end
end
end
end

2 个答案:

答案 0 :(得分:0)

您的路线转到操作feed,但您的respond_to块对应于操作index。你可能想要:

match '/feed' => 'articles#index', :as => :feed, :defaults => { :format => 'atom' }

答案 1 :(得分:0)

在您的申请模板(application.html.rb)中,请尝试以下方式:

<%= auto_discovery_link_tag(:atom, feed_path, { :title => "My ATOM Feed" }) %>