Skip to content

Commit 61718dd

Browse files
Add Atom feed view
[#1]
1 parent 8a80a88 commit 61718dd

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

app/controllers/tweets_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
class TweetsController < ApplicationController
2+
def index
3+
@tweets = Tweet.first 20
4+
end
25

36
def show
47
@tweet = Tweet.find(params[:id])

app/views/tweets/index.atom.builder

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
atom_feed root_url: tweets_url do |feed|
2+
feed.title "RubyFriends"
3+
feed.updated @tweets.first.updated_at
4+
5+
@tweets.each do |tweet|
6+
feed.entry tweet, url: tweet.media_display_url, id: tweet.tweet_id do |entry|
7+
entry.url tweet.media_display_url
8+
entry.title "@#{tweet.username}: #{tweet.tweet_text.truncate 50}"
9+
entry.content tweet.tweet_text, type: :html
10+
entry.updated tweet.updated_at.iso8601
11+
12+
entry.author do |author|
13+
author.name "@#{tweet.username}"
14+
end
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)