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:
Senén Rodero Rodríguez
2019-02-21 20:02:38 +01:00
committed by voodoorai2000
parent e847aa22f7
commit ce7be5f2d6
3 changed files with 8 additions and 3 deletions

View File

@@ -12,6 +12,10 @@ module Notifiable
end
end
def notifiable_body
body if attribute_names.include?("body")
end
def notifiable_available?
case self.class.name
when "ProposalNotification"

View File

@@ -11,8 +11,9 @@ class Notification < ApplicationRecord
scope :recent, -> { order(id: :desc) }
scope :for_render, -> { includes(:notifiable) }
delegate :notifiable_title, :notifiable_available?, :check_availability,
:linkable_resource, to: :notifiable, allow_nil: true
delegate :notifiable_title, :notifiable_body, :notifiable_available?,
:check_availability, :linkable_resource,
to: :notifiable, allow_nil: true
def mark_as_read
update(read_at: Time.current)

View File

@@ -3,7 +3,7 @@
<% locals = { notification: notification,
timestamp: notification.timestamp,
title: notification.notifiable_title,
body: notification.notifiable.try(:body) } %>
body: notification.notifiable_body } %>
<% link_text = render partial: "/notifications/notification_body", locals: locals %>
<%= link_to_if notification.link.present?, link_text, notification.link %>
<% else %>