Change the way to retrieve notifiable body
Using 'try' method to get notifiable is not working with translations anymore. It was returning 'nil' always even when body translation is populated.
This commit is contained in:
committed by
voodoorai2000
parent
e847aa22f7
commit
ce7be5f2d6
@@ -12,6 +12,10 @@ module Notifiable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notifiable_body
|
||||||
|
body if attribute_names.include?("body")
|
||||||
|
end
|
||||||
|
|
||||||
def notifiable_available?
|
def notifiable_available?
|
||||||
case self.class.name
|
case self.class.name
|
||||||
when "ProposalNotification"
|
when "ProposalNotification"
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ class Notification < ApplicationRecord
|
|||||||
scope :recent, -> { order(id: :desc) }
|
scope :recent, -> { order(id: :desc) }
|
||||||
scope :for_render, -> { includes(:notifiable) }
|
scope :for_render, -> { includes(:notifiable) }
|
||||||
|
|
||||||
delegate :notifiable_title, :notifiable_available?, :check_availability,
|
delegate :notifiable_title, :notifiable_body, :notifiable_available?,
|
||||||
:linkable_resource, to: :notifiable, allow_nil: true
|
:check_availability, :linkable_resource,
|
||||||
|
to: :notifiable, allow_nil: true
|
||||||
|
|
||||||
def mark_as_read
|
def mark_as_read
|
||||||
update(read_at: Time.current)
|
update(read_at: Time.current)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<% locals = { notification: notification,
|
<% locals = { notification: notification,
|
||||||
timestamp: notification.timestamp,
|
timestamp: notification.timestamp,
|
||||||
title: notification.notifiable_title,
|
title: notification.notifiable_title,
|
||||||
body: notification.notifiable.try(:body) } %>
|
body: notification.notifiable_body } %>
|
||||||
<% link_text = render partial: "/notifications/notification_body", locals: locals %>
|
<% link_text = render partial: "/notifications/notification_body", locals: locals %>
|
||||||
<%= link_to_if notification.link.present?, link_text, notification.link %>
|
<%= link_to_if notification.link.present?, link_text, notification.link %>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|||||||
Reference in New Issue
Block a user