mongo_mapper custom data types for localization
Posted
by
rick
on Stack Overflow
See other posts from Stack Overflow
or by rick
Published on 2011-02-17T15:21:34Z
Indexed on
2011/02/17
15:25 UTC
Read the original article
Hit count: 270
hi
i have created a LocalizedString custom data type for storing / displaying translations using mongo_mapper.
This works for one field but as soon as i introduce another field they get written over each and display only one value for both fields. The to_mongo and from_mongo seem to be not workings properly. Please can any one help with this ? her is the code :
class LocalizedString
attr_accessor :translations
def self.from_mongo(value)
puts self.inspect
@translations ||= if value.is_a?(Hash)
value
elsif value.nil?
{}
else
{ I18n.locale.to_s => value }
end
@translations[I18n.locale.to_s]
end
def self.to_mongo(value) puts self.inspect if value.is_a?(Hash) @translations = value
else
@translations[I18n.locale.to_s] = value
end
@translations
end end
Thank alot Rick
© Stack Overflow or respective owner