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 module Panel::UserHelper
def show_user_attribute(object, key, locale = '') 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) } 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 locale.to_s.blank? if attribute
attribute['key'] if locale.to_s.blank?
attribute['key']
else
attribute[locale.to_s]
end
else else
attribute[locale.to_s] ''
end end
end end