diff options
author | David Cabo <david@calibea.com> | 2011-08-16 03:50:11 +0200 |
---|---|---|
committer | David Cabo <david@calibea.com> | 2011-08-16 12:22:21 +0200 |
commit | 95e357b02b75de103d93180e3a33417f0c83dfb3 (patch) | |
tree | 4640212275cd028ac1889631791cc89a97dc746d /app/models | |
parent | 19b54415ca0f2177aa1786a7deba5b4a5f1ce1df (diff) |
Don't fail if a body has the same url_name in several locales (closes #139)
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/public_body.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index ef1d60e26..b75da4331 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -54,15 +54,16 @@ class PublicBody < ActiveRecord::Base # like find_by_url_name but also search historic url_name if none found def self.find_by_url_name_with_historic(name) - @locale = I18n.locale.to_s - PublicBody.with_locale(@locale) do + locale = self.locale || I18n.locale + PublicBody.with_locale(locale) do found = PublicBody.find(:all, :conditions => ["public_body_translations.url_name='#{name}'"], :joins => :translations, :readonly => false) - 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 many bodies are found (usually because the url_name is the same across + # locales) return any of them + return found.first 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 @@ -138,7 +139,7 @@ class PublicBody < ActiveRecord::Base return 'defunct' elsif self.not_apply? return 'not_apply' - elsif self.request_email.empty? or self.request_email == 'blank' + elsif self.request_email.nil? or self.request_email.empty? or self.request_email == 'blank' return 'bad_contact' else raise "requestable_failure_reason called with type that has no reason" |