Atom Web 订阅
修改我们的 Post Controller index 方法
app/controlllers/posts_controller.rb
class PostsController < ApplicationController
...
def index
@posts = Post.all
respond_to do |format|
format.html
format.atom
end
end
...
end
创建要 Atom 的页面
app/views/posts/index.atom.builder
atom_feed do |feed|
feed.title "aRailsDemo"
feed.subtitle "Building This Site"
feed.updated @posts.first.created_at
for post in @posts
feed.entry(post, :url => post_url(post.sequence)) do |entry|
entry.title post.title
entry.content post.description, :type => 'html'
entry.author do |author|
author.name "aRailsDemo"
end
end
end
end
布局渲染/侧边栏提供链接
app/views/layouts/application.html.haml 和 app/views/shared/_sidebar.html.haml
# application.html.haml
...
...
#container
...
#sidebar
#innerSidebar
= render 'shared/sidebar'
___________________________________
# _sidebar.html.haml
%p.feedButton= link_to "Subscribe", "http://feeds.feedburner.com/arailsdemo"
auto_discovery_link_tag 辅助方法
如果我们使用 auto_discovery_link_tag, 很多‘浏览器’ 就能够知道我们是在浏览订阅信息。
app/views/layouts/application.html.haml
!!!
%html(lang="en")
%head
...
= auto_discovery_link_tag :atom, "http://feeds.feedburner.com/arailsdemo"