Commit 188e5d3b by tady

create notifications table

parent 09d06742
class Notification < ActiveRecord::Base
belongs_to :user
end
...@@ -37,6 +37,7 @@ class User < ActiveRecord::Base ...@@ -37,6 +37,7 @@ class User < ActiveRecord::Base
###################################################################### ######################################################################
has_many :posts, foreign_key: 'author_id' has_many :posts, foreign_key: 'author_id'
has_many :comments, foreign_key: 'author_id' has_many :comments, foreign_key: 'author_id'
has_many :notifications
###################################################################### ######################################################################
# scope # scope
...@@ -105,6 +106,10 @@ class User < ActiveRecord::Base ...@@ -105,6 +106,10 @@ class User < ActiveRecord::Base
) )
end end
# push通知を追加
def push_notification(detail_path, body)
notifications.create(detail_path: detail_path, body: body, is_read: false)
end
end end
...@@ -41,5 +41,17 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation" ...@@ -41,5 +41,17 @@ nav.navbar.navbar-default.navbar-fixed-top role="navigation"
li.divider li.divider
li li
a href=me_session_path data-method="delete" rel="nofollow" SignOut a href=me_session_path data-method="delete" rel="nofollow" SignOut
li.dropdown
a.dropdown-toggle data-toggle="dropdown"
| 通知
span.badge = current_user.decorate.draft_count
b.caret
ul.dropdown-menu
- current_user.notifications.each do |notification|
li
a href=notification.detail_path
= notification.body
span.badge.pull-right = current_user.decorate.draft_count
class CreateNotifications < ActiveRecord::Migration
def change
create_table :notifications do |t|
t.integer :user_id
t.datetime :read_at
t.boolean :is_read, null: false, default: false
t.string :detail_path
t.text :body
t.timestamps
end
add_index :notifications, [:user_id, :is_read, :read_at]
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140420120819) do ActiveRecord::Schema.define(version: 20140501045300) do
create_table "comments", force: true do |t| create_table "comments", force: true do |t|
t.integer "author_id" t.integer "author_id"
...@@ -24,6 +24,18 @@ ActiveRecord::Schema.define(version: 20140420120819) do ...@@ -24,6 +24,18 @@ ActiveRecord::Schema.define(version: 20140420120819) do
add_index "comments", ["author_id", "updated_at"], name: "index_comments_on_author_id_and_updated_at", using: :btree add_index "comments", ["author_id", "updated_at"], name: "index_comments_on_author_id_and_updated_at", using: :btree
add_index "comments", ["post_id", "updated_at"], name: "index_comments_on_post_id_and_updated_at", using: :btree add_index "comments", ["post_id", "updated_at"], name: "index_comments_on_post_id_and_updated_at", using: :btree
create_table "notifications", force: true do |t|
t.integer "user_id"
t.datetime "read_at"
t.boolean "is_read", default: false, null: false
t.string "detail_path"
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "notifications", ["user_id", "is_read", "read_at"], name: "index_notifications_on_user_id_and_is_read_and_read_at", using: :btree
create_table "post_tags", force: true do |t| create_table "post_tags", force: true do |t|
t.integer "post_id", null: false t.integer "post_id", null: false
t.integer "tag_id", null: false t.integer "tag_id", null: false
......
require 'spec_helper'
describe Notifications do
pending "add some examples to (or delete) #{__FILE__}"
end
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