अगर मैं आपकी स्थिति पर कोई टिप्पणी लिखता हूं और फिर आप टिप्पणी करते हैं तो मुझे आपको सूचित करने के लिए अधिसूचना नहीं मिलती है कि आपने टिप्पणी की है।टिप्पणीकर्ता को कैसे सूचित करें?
वर्तमान में केवल स्थिति के मालिक को सूचनाएं मिलती हैं। हम कैसे बना सकते हैं, जहां किसी भी स्थिति पर टिप्पणी करने वाले किसी भी व्यक्ति को अधिसूचित किया जाना चाहिए?
मॉडल
class Comment < ActiveRecord::Base
after_save :create_notification
has_many :notifications
def create_notification
author = valuation.user
notifications.create(
comment: self,
valuation: valuation,
user: author,
read: false
)
end
end
class Notification < ActiveRecord::Base
belongs_to :comment
belongs_to :valuation
belongs_to :user
end
class Valuation < ActiveRecord::Base
belongs_to :user
has_many :notifications
has_many :comments
end
नियंत्रकों
class CommentsController < ApplicationController
before_action :set_commentable, only: [:index, :new, :create]
before_action :set_comment, only: [:edit, :update, :destroy]
def create
@comment = @commentable.comments.new(comment_params)
if @comment.save
redirect_to @commentable, notice: "Comment created."
else
render :new
end
end
private
def set_commentable
@commentable = find_commentable
end
def set_comment
@comment = current_user.comments.find(params[:id])
end
def find_commentable
if params[:goal_id]
Goal.find(params[:goal_id])
elsif params[:habit_id]
Habit.find(params[:habit_id])
elsif params[:valuation_id]
Valuation.find(params[:valuation_id])
elsif params[:stat_id]
Stat.find(params[:stat_id])
end
end
end
class NotificationsController < ApplicationController
def index
@notifications = current_user.notifications
@notifications.each do |notification|
notification.update_attribute(:read, true)
end
end
end
विचारों
#notifications/_notification.html.erb
commented on <%= link_to "your value", notification_valuation_path(notification, notification.valuation_id) %>
#comments/_form.html.erb
<%= form_for [@commentable, @comment] do |f| %>
<%= f.text_area :content %>
<% end %>
आपका प्रश्न बहुत सामान्य है। _ "जब भी कोई उपयोगकर्ता किसी स्थिति पर टिप्पणी करता है तो उस स्थिति के बाद आने वाली किसी भी टिप्पणी ** आपको सूचित करनी चाहिए ** कि एक अतिरिक्त टिप्पणी की गई है" _। आपको क्या जानने की जरूरत है? क्या आप सूचित करने के लिए _when_ को कैसे जानना चाहते हैं, या आप उपयोगकर्ता को सूचित करने के लिए _how_ के बारे में पूछ रहे हैं? _notifying_ द्वारा आपका क्या मतलब है? मॉडल में कुछ मूल्य बदल दिए गए, एक ईमेल भेजा गया, एक पॉपअप ... – brito
यदि मैं आपके मूल्य पर टिप्पणी करता हूं। फिर यदि आप उस मूल्य पर वापस टिप्पणी करते हैं। मुझे एक अधिसूचना नहीं मिली है जो आपको बताती है कि आपने टिप्पणी की है। केवल वह व्यक्ति जिसका मूल्य इसे अधिसूचना प्राप्त करता है। हो सकता है कि इस काम को बनाने के लिए 'def create_notification' में कोई तरीका है @brito –
@ AnthonyGalli.com हां, क्योंकि अधिसूचना हमेशा उपयोगकर्ता: लेखक,', और 'लेखक = वैल्यूएशन.यूसर' के साथ बनाई जाती है (यह ' create_notification')। तो आपको 'वैल्यूएशन' लेखक की बजाय 'टिप्पणी' के लेखक को पारित करने वाली उस विशिष्ट अधिसूचना को बनाने की आवश्यकता है। – brito