añadir track_activity para mostrar futuras notificaciones a los usuarios

This commit is contained in:
Julian Herrero
2015-10-06 12:05:34 +02:00
committed by rgarcia
parent 5e9240e25c
commit ba0ce4e14b
6 changed files with 20 additions and 3 deletions

View File

@@ -108,4 +108,12 @@ class ApplicationController < ActionController::Base
store_location_for(:user, request.path) store_location_for(:user, request.path)
end end
end end
def track_activity(trackable)
if trackable.is_a? Comment
action = trackable.root? ? "debate_comment" : "comment_reply"
activity = current_user.activities.create! action: action, trackable: trackable
add_notifications_for activity
end
end
end end

View File

@@ -9,6 +9,7 @@ class CommentsController < ApplicationController
def create def create
if @comment.save if @comment.save
CommentNotifier.new(comment: @comment).process CommentNotifier.new(comment: @comment).process
track_activity @comment
else else
render :new render :new
end end

View File

@@ -1,5 +1,4 @@
class Activity < ActiveRecord::Base class Activity < ActiveRecord::Base
belongs_to :actionable, -> { with_hidden }, polymorphic: true belongs_to :actionable, -> { with_hidden }, polymorphic: true
belongs_to :user, -> { with_hidden } belongs_to :user, -> { with_hidden }
@@ -24,5 +23,4 @@ class Activity < ActiveRecord::Base
def self.by(user) def self.by(user)
where(user: user) where(user: user)
end end
end end

View File

@@ -0,0 +1,9 @@
class CreateActivities < ActiveRecord::Migration
def change
create_table :activities do |t|
t.belongs_to :user, index: true, foreign_key: true
t.string :action
t.belongs_to :trackable, polymorphic: true
end
end
end

View File

@@ -396,6 +396,7 @@ ActiveRecord::Schema.define(version: 20151215165824) do
add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree add_index "votes", ["votable_id", "votable_type", "vote_scope"], name: "index_votes_on_votable_id_and_votable_type_and_vote_scope", using: :btree
add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree
add_foreign_key "activities", "users"
add_foreign_key "administrators", "users" add_foreign_key "administrators", "users"
add_foreign_key "annotations", "legislations" add_foreign_key "annotations", "legislations"
add_foreign_key "annotations", "users" add_foreign_key "annotations", "users"