From 3820e979a998918a514bd4956c89b6a9b3035b20 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Tue, 22 Mar 2016 17:15:38 -0300 Subject: [PATCH] comment: make explicit fail-safe relation with profile and environment --- app/models/comment.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/comment.rb b/app/models/comment.rb index 95d3654..ce8eed2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -115,7 +115,15 @@ class Comment < ActiveRecord::Base end delegate :environment, :to => :profile - delegate :profile, :to => :source, :allow_nil => true + + def environment + profile && profile.respond_to?(:environment) ? profile.environment : nil + end + + def profile + return unless source + source.kind_of?(Profile) ? source : source.profile + end include Noosfero::Plugin::HotSpot -- libgit2 0.21.2