aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/public_body.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/public_body.rb')
-rw-r--r--app/models/public_body.rb40
1 files changed, 23 insertions, 17 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 3d2b180b8..b68722b81 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -46,28 +46,34 @@ class PublicBody < ActiveRecord::Base
translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme
+ # Make sure publication_scheme gets the correct default value.
+ # (This would work automatically, were publication_scheme not a translated attribute)
+ def after_initialize
+ self.publication_scheme = "" if self.publication_scheme.nil?
+ end
+
# like find_by_url_name but also search historic url_name if none found
def self.find_by_url_name_with_historic(name)
@localer = I18n.locale.to_s
PublicBody.with_locale(@locale) do
found = PublicBody.find(:all,
- :conditions => ["public_body_translations.url_name='#{name}' AND public_body_translations.locale = '#{@localer}'"],
- :joins => :translations)
- return found.first if found.size == 1
- # Shouldn't we just make url_name unique?
- raise "Two bodies with the same URL name: #{name}" if found.size > 1
- # If none found, then search the history of short names
- old = PublicBody::Version.find_all_by_url_name(name)
- # Find unique public bodies in it
- old = old.map { |x| x.public_body_id }
- old = old.uniq
- # Maybe return the first one, so we show something relevant,
- # rather than throwing an error?
- raise "Two bodies with the same historical URL name: #{name}" if old.size > 1
- return unless old.size == 1
- # does acts_as_versioned provide a method that returns the current version?
- return PublicBody.find(old.first)
- end
+ :conditions => ["public_body_translations.url_name='#{name}' AND public_body_translations.locale = '#{@localer}'"],
+ :joins => :translations)
+ return found.first if found.size == 1
+ # Shouldn't we just make url_name unique?
+ raise "Two bodies with the same URL name: #{name}" if found.size > 1
+ # If none found, then search the history of short names
+ old = PublicBody::Version.find_all_by_url_name(name)
+ # Find unique public bodies in it
+ old = old.map { |x| x.public_body_id }
+ old = old.uniq
+ # Maybe return the first one, so we show something relevant,
+ # rather than throwing an error?
+ raise "Two bodies with the same historical URL name: #{name}" if old.size > 1
+ return unless old.size == 1
+ # does acts_as_versioned provide a method that returns the current version?
+ return PublicBody.find(old.first)
+ end
end