6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/coupler/extensions/notifications.rb', line 6
def self.registered(app)
app.before do
Notification.filter(~{:seen => true}, {:url => request.path_info}).update(:seen => true)
end
app.get "/notifications" do
@notifications = Notification.order(:created_at).all
erb :"notifications/index"
end
app.get "/notifications/unseen.json" do
content_type 'application/json'
notifications = Notification.filter(~{:seen => true}).order(:created_at).all
notifications.collect do |n|
{ 'id' => n.id, 'message' => n.message, 'url' => n.url, 'created_at' => n.created_at.iso8601 }
end.to_json
end
end
|