Rescue nil values for attribute_values in User

This commit is contained in:
chris2tof 2011-11-16 09:47:09 +08:00
parent bcf487f264
commit c4810274ec
1 changed files with 8 additions and 4 deletions

View File

@ -1,11 +1,15 @@
module Panel::UserHelper
def show_user_attribute(object, key, locale = '')
attribute = object.attribute_values.detect {|av| av.key.to_s.eql?(key.to_s) || av[locale.to_s].eql?(locale.to_s) }
if locale.to_s.blank?
attribute['key']
attribute = object.attribute_values.detect {|av| av.key.to_s.eql?(key.to_s) || av[locale.to_s].eql?(locale.to_s) } rescue nil
if attribute
if locale.to_s.blank?
attribute['key']
else
attribute[locale.to_s]
end
else
attribute[locale.to_s]
''
end
end