When displaying changes, use '-' if id of associated object is blank
This commit is contained in:
parent
75ee1371de
commit
b30afccfba
2 changed files with 4 additions and 3 deletions
|
|
@ -397,6 +397,7 @@ module ApplicationHelper
|
||||||
# Returns object in its current state if its alive
|
# Returns object in its current state if its alive
|
||||||
# Otherwise Returns object state just before deletion
|
# Otherwise Returns object state just before deletion
|
||||||
def current_or_last_object_state(model_name, id)
|
def current_or_last_object_state(model_name, id)
|
||||||
|
return nil unless id.present? && model_name.present?
|
||||||
begin
|
begin
|
||||||
object = model_name.constantize.find_by(id: id)
|
object = model_name.constantize.find_by(id: id)
|
||||||
rescue NameError
|
rescue NameError
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,11 @@
|
||||||
%td
|
%td
|
||||||
- associated_object = current_or_last_object_state(model_name, values[0])
|
- associated_object = current_or_last_object_state(model_name, values[0])
|
||||||
= associated_object.try(:title) || associated_object.try(:name)
|
= associated_object.try(:title) || associated_object.try(:name)
|
||||||
= "(ID: #{values[0].blank? ? '-' : values[0]})"
|
= values[0].blank? ? '-' : "(ID: #{values[0]})"
|
||||||
%td
|
%td
|
||||||
- associated_object = current_or_last_object_state(model_name, values[1])
|
- associated_object = current_or_last_object_state(model_name, values[1])
|
||||||
= associated_object.try(:title) || associated_object.try(:name)
|
= associated_object.try(:title) || associated_object.try(:name)
|
||||||
= "(ID: #{values[1].blank? ? '-' : values[1]})"
|
= (values[1].blank? ? '-' : "(ID: #{values[1]})")
|
||||||
|
|
||||||
- else
|
- else
|
||||||
- if version.event != 'create'
|
- if version.event != 'create'
|
||||||
|
|
@ -46,6 +46,6 @@
|
||||||
%td
|
%td
|
||||||
- associated_object = current_or_last_object_state(model_name, value)
|
- associated_object = current_or_last_object_state(model_name, value)
|
||||||
= associated_object.try(:title) || associated_object.try(:name)
|
= associated_object.try(:title) || associated_object.try(:name)
|
||||||
= "(ID: #{value.blank? ? '-' : value})"
|
= value.blank? ? '-' : "(ID: #{value})"
|
||||||
- else
|
- else
|
||||||
%td= value.blank? ? '-' : value
|
%td= value.blank? ? '-' : value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue