Commit 9f411a7e by tady

headerの通知view作成

parent 188e5d3b
class NotificationsController < ApplicationController
before_action :set_notification, only: [:bridge]
def bridge
@notification.set_read!
redirect_to @notification.detail_path
end
private
def set_notification
@notification = Notification.find(params[:id])
end
end
class Notification < ActiveRecord::Base class Notification < ActiveRecord::Base
belongs_to :user belongs_to :user
######################################################################
# Named scope
######################################################################
# 最新のPostを取得
scope :unread, -> {
where(is_read: false)
}
######################################################################
# Instance method
######################################################################
# 既読にする
def set_read!
update!(is_read: true, read_at: Time.now)
end
end end
...@@ -44,14 +44,18 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation" ...@@ -44,14 +44,18 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
li.dropdown li.dropdown
a.dropdown-toggle data-toggle="dropdown" a.dropdown-toggle data-toggle="dropdown"
| 通知 | 通知
span.badge = current_user.decorate.draft_count - if current_user.notifications.unread.any?
span.badge = current_user.notifications.unread.count
b.caret b.caret
ul.dropdown-menu ul.dropdown-menu
- current_user.notifications.each do |notification| - if current_user.notifications.unread.any?
- current_user.notifications.unread.each do |notification|
li
a href=notification_bridge_path(notification.id)
= notification.body
- else
li li
a href=notification.detail_path a 通知はありません
= notification.body
span.badge.pull-right = current_user.decorate.draft_count
...@@ -18,6 +18,8 @@ Rendezvous::Application.routes.draw do ...@@ -18,6 +18,8 @@ Rendezvous::Application.routes.draw do
get 'posts/:id/slideshow' => 'posts#slideshow', as: 'slideshow_post' get 'posts/:id/slideshow' => 'posts#slideshow', as: 'slideshow_post'
resources :posts, except: [:index] resources :posts, except: [:index]
get 'notification_bridge/:id' => 'notifications#bridge', as: 'notification_bridge'
post 'tags/:name/merge_to/:merge_to_name' => 'tags#merge_to', as: 'merge_to_tag' post 'tags/:name/merge_to/:merge_to_name' => 'tags#merge_to', as: 'merge_to_tag'
post 'tags/:name/move_to/:move_to_name' => 'tags#move_to', as: 'move_to_tag' post 'tags/:name/move_to/:move_to_name' => 'tags#move_to', as: 'move_to_tag'
resources :tags, :param => :name, except: [:index] resources :tags, :param => :name, except: [:index]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment