aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-12-02 16:00:56 +0000
committerSeb Bacon <seb.bacon@gmail.com>2011-12-02 16:00:56 +0000
commit00caf911d7b60cbd3dea0ec070321b5b6aa6a79d (patch)
treef375c901599c8e655eb9fd27d7017d62949976bd
parentdc3c642e889f887e46873ae78967ec7c893c9c1b (diff)
Don't make any entries in the translations table for bodies with entirely empty strings in all their fields. See issue #280.
-rw-r--r--app/models/public_body.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index b35c56018..453e3a6cf 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -64,8 +64,14 @@ class PublicBody < ActiveRecord::Base
end
def translated_versions=(translation_attrs)
+ def skip?(attrs)
+ valueless = attrs.inject({}) { |h, (k, v)| h[k] = v if v != '' and k != 'locale'; h } # because we want to fall back to alternative translations where there are empty values
+ return valueless.length == 0
+ end
+
if translation_attrs.respond_to? :each_value # Hash => updating
translation_attrs.each_value do |attrs|
+ next if skip?(attrs)
t = translation(attrs[:locale]) || PublicBody::Translation.new
t.attributes = attrs
calculate_cached_fields(t)
@@ -73,6 +79,7 @@ class PublicBody < ActiveRecord::Base
end
else # Array => creating
translation_attrs.each do |attrs|
+ next if skip?(attrs)
new_translation = PublicBody::Translation.new(attrs)
calculate_cached_fields(new_translation)
translations << new_translation