Files
grecia/app/models/concerns/notifiable.rb
Senén Rodero Rodríguez ce7be5f2d6 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.
2019-06-27 09:19:36 +02:00

40 lines
764 B
Ruby

module Notifiable
extend ActiveSupport::Concern
def notifiable_title
case self.class.name
when "ProposalNotification"
proposal.title
when "Comment"
commentable.title
else
title
end
end
def notifiable_body
body if attribute_names.include?("body")
end
def notifiable_available?
case self.class.name
when "ProposalNotification"
check_availability(proposal)
when "Comment"
check_availability(commentable)
else
check_availability(self)
end
end
def check_availability(resource)
resource.present? &&
resource.try(:hidden_at).nil? &&
resource.try(:retired_at).nil?
end
def linkable_resource
is_a?(ProposalNotification) ? proposal : self
end
end