-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
FabienNeibaf
committed
Sep 20, 2019
1 parent
cfee2c6
commit 4a0a18a
Showing
10 changed files
with
66 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class NotificationsController < ApplicationController | ||
def show | ||
notif = Notification.find(params[:id]) | ||
if notif | ||
notif.read! | ||
if notif.subject.respond_to?(:post) | ||
redirect_to notif.subject.post | ||
else | ||
redirect_to notif.sender | ||
end | ||
else | ||
redirect_to root_url | ||
end | ||
end | ||
|
||
def index | ||
@notifs = Notification.where(receiver_id: current_user.id) | ||
@notifs = Notification.where(receiver_id: current_user.id).unread | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class Notification < ApplicationRecord | ||
enum read_status: %i[unread read] | ||
|
||
belongs_to :sender, class_name: 'User' | ||
belongs_to :receiver, class_name: 'User' | ||
belongs_to :subject, polymorphic: true | ||
belongs_to :receiver, class_name: 'User' | ||
|
||
validates :sender, :receiver, :content, :subject, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<li> | ||
<%= link_to notif do %> | ||
<span class="photo"> | ||
<%= image_tag(photo_path(notif.sender)) %> | ||
</span> | ||
<%= notif.content %> | ||
<% end %> | ||
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
db/migrate/20190920065351_add_read_status_to_notifications.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddReadStatusToNotifications < ActiveRecord::Migration[5.2] | ||
def change | ||
add_column :notifications, :read_status, :integer, limit: 1, default: 0 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters