-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrss.rb
More file actions
101 lines (77 loc) · 1.66 KB
/
rss.rb
File metadata and controls
101 lines (77 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# RSS Feed Reader: Users subscribe to RSS and Atom feeds, and get a list of posts they can read and favorite.
class User
has_many :subscriptions
has_many :feeds, through: :subscriptions
belongs_to :timeline
has_many :favorites
def favorite(item)
favorites.create_or_find_by! item:
end
def unfavorite(item)
favorites.destroy_by item:
end
end
class Subscription
belongs_to :user
belongs_to :feed
end
class Feed
has_many :subscriptions
has_many :users, through: :subscriptions
# url
def public?
!personal?
end
def personal?
password_details?
end
end
class Feed::Post
end
class User::Timeline
has_many :items
end
class User::Favorite
belongs_to :user
belongs_to :item
end
class User::Timeline::Item
belongs_to :timeline
belongs_to :post
# accepted_at
# rejected_at
belongs_to :download, optional: true
end
class User::TimelinesController < ApplicationController
def show
@items = Current.user.timeline.items.order(:created_at)
end
end
# app/views/user/timelines/show.html.erb
@items.each do |item|
if Current.user.favorite?(item)
button_to unfavorite_item_path(item), method: :delete
else
button_to favorite_item_path(item)
end
end
class User::Items::FavoritesController < ApplicationController
def show
end
def create
@item = Current.user.timeline.items.find(params[:id])
Current.user.favorite @item
end
def destroy
@item = Current.user.timeline.items.find(params[:id])
Current.user.unfavorite @item
end
end
resources :users do
namespace :timeline do
resources :favorites
end
end
class Current < ActiveSupport::CurrentAttributes
attribute :user
end