开发者

Rails 3 - help with Atom Feed?

Feel like I have been going around in circles, have followed different tutorials all proposing to achieve the promised result and none of them are working for me. I'm using the Kaminari plug-in and my articles are on the index page (6).Can anyone help me with this? 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开发者_如何学C => @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


Your route goes to an action feed but your respond_to block corresponds to the action index. You probably want:

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


In your application template (application.html.rb), try this instead:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜