aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2011-03-25 15:20:59 +0000
committerSeb Bacon <seb.bacon@gmail.com>2011-03-25 15:20:59 +0000
commit2bb79f893805e972f6efe5cb7cfe90dd0efa4107 (patch)
tree47084acc8d48126b9e891bb50c217be43be27641 /app/models
parent22c25e42847d41924d43d31f3ef67be1ae4a155e (diff)
parent1fb57d66c22000d4164c033ffd9353aa9030255b (diff)
resolve merge conflicts
Diffstat (limited to 'app/models')
-rw-r--r--app/models/public_body.rb17
1 files changed, 13 insertions, 4 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 446ac2334..51d6ea914 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -44,6 +44,9 @@ class PublicBody < ActiveRecord::Base
has_tag_string
+ translates :name, :short_name, :request_email, :url_name, :notes
+ translates :first_letter, :publication_scheme
+
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)
found = PublicBody.find_all_by_url_name(name)
@@ -67,7 +70,8 @@ class PublicBody < ActiveRecord::Base
# Set the first letter, which is used for faster queries
before_save(:set_first_letter)
def set_first_letter
- self.first_letter = self.name[0,1].upcase
+ # we use a regex to ensure it works with utf-8/multi-byte
+ self.first_letter = self.name.scan(/./mu)[0].upcase
end
def validate
@@ -166,16 +170,21 @@ class PublicBody < ActiveRecord::Base
# When name or short name is changed, also change the url name
def short_name=(short_name)
- write_attribute(:short_name, short_name)
+ globalize.write(self.class.locale || I18n.locale, :short_name, short_name)
+ self[:short_name] = short_name
+ globalize.save_translations!
self.update_url_name
end
def name=(name)
- write_attribute(:name, name)
+ globalize.write(self.class.locale || I18n.locale, :name, name)
+ self[:name] = name
+ globalize.save_translations!
self.update_url_name
end
+
def update_url_name
url_name = MySociety::Format.simplify_url_part(self.short_or_long_name, 'body')
- write_attribute(:url_name, url_name)
+ self.url_name = url_name
end
# Return the short name if present, or else long name
def short_or_long_name