Rails 3 - help with Atom Feed?



感觉我一直在兜圈子,遵循了不同的教程,所有教程都建议实现承诺的结果,但没有一个对我有效。我正在使用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

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

您的路由指向动作feed,但responsd_to块对应于动作index。你可能想要:

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

在应用程序模板(application.html.rb)中,请尝试以下操作:

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

最新更新