diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 88b89806..1d3e4bea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -397,6 +397,7 @@ module ApplicationHelper # Returns object in its current state if its alive # Otherwise Returns object state just before deletion def current_or_last_object_state(model_name, id) + return nil unless id.present? && model_name.present? begin object = model_name.constantize.find_by(id: id) rescue NameError diff --git a/app/views/shared/_object_changes.html.haml b/app/views/shared/_object_changes.html.haml index d01f35b6..69a9dd80 100644 --- a/app/views/shared/_object_changes.html.haml +++ b/app/views/shared/_object_changes.html.haml @@ -23,11 +23,11 @@ %td - associated_object = current_or_last_object_state(model_name, values[0]) = associated_object.try(:title) || associated_object.try(:name) - = "(ID: #{values[0].blank? ? '-' : values[0]})" + = values[0].blank? ? '-' : "(ID: #{values[0]})" %td - associated_object = current_or_last_object_state(model_name, values[1]) = associated_object.try(:title) || associated_object.try(:name) - = "(ID: #{values[1].blank? ? '-' : values[1]})" + = (values[1].blank? ? '-' : "(ID: #{values[1]})") - else - if version.event != 'create' @@ -46,6 +46,6 @@ %td - associated_object = current_or_last_object_state(model_name, value) = associated_object.try(:title) || associated_object.try(:name) - = "(ID: #{value.blank? ? '-' : value})" + = value.blank? ? '-' : "(ID: #{value})" - else %td= value.blank? ? '-' : value