Added creator_link and updator_link helpers

This commit is contained in:
Priit Tark 2015-03-23 11:17:27 +02:00
parent 15272bad76
commit d8d951974e
3 changed files with 24 additions and 7 deletions

View file

@ -17,4 +17,20 @@ module ApplicationHelper
"#{contact.ident} [#{contact.ident_country_code} #{contact.ident_type}]"
end
end
def creator_link(model)
return 'not present' if model.blank?
return model if model.kind_of? String
# can be api user or some other user
link_to(model.creator, ['admin', model.creator])
end
def updator_link(model)
return 'not present' if model.blank?
return model if model.kind_of? String
# can be api user or some other user
link_to(model.creator, ['admin', model.updator])
end
end

View file

@ -27,21 +27,25 @@ module Versions
def creator
return nil if creator_str.blank?
if creator_str =~ /^\d-api-/
creator = if creator_str =~ /^\d-api-/
ApiUser.find_by(id: creator_str)
else
AdminUser.find_by(id: creator_str)
end
creator.present? ? creator : creator_str
end
def updator
return nil if updator_str.blank?
if updator_str =~ /^\d-api-/
updator = if updator_str =~ /^\d-api-/
ApiUser.find_by(id: updator_str)
else
AdminUser.find_by(id: updator_str)
end
updator.present? ? updator : updator_str
end
# callbacks

View file

@ -32,18 +32,15 @@
%dd
= l(@contact.created_at, format: :short)
by
= link_to(@contact.creator, [:admin, @contact.creator])
= creator_link(@contact)
%dt= t(:updated)
%dd
= l(@contact.updated_at, format: :short)
by
= link_to(@contact.updator, [:admin, @contact.updator])
= updator_link(@contact)
%dt= t(:registrar)
%dd
- if @contact.registrar.present?
= link_to(@contact.registrar, admin_registrar_path(@contact.registrar))