diff options
Diffstat (limited to 'app/models/public_body.rb')
-rw-r--r-- | app/models/public_body.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 60ecb2781..77da81d4c 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -45,6 +45,8 @@ class PublicBody < ActiveRecord::Base has_many :censor_rules, :order => 'created_at desc' has_tag_string + before_save :set_api_key, :set_default_publication_scheme + translates :name, :short_name, :request_email, :url_name, :notes, :first_letter, :publication_scheme @@ -89,13 +91,13 @@ class PublicBody < ActiveRecord::Base end end - def after_initialize + def set_default_publication_scheme # Make sure publication_scheme gets the correct default value. # (This would work automatically, were publication_scheme not a translated attribute) self.publication_scheme = "" if self.publication_scheme.nil? end - def before_save + def set_api_key self.api_key = SecureRandom.base64(33) if self.api_key.nil? end @@ -104,7 +106,7 @@ class PublicBody < ActiveRecord::Base locale = self.locale || I18n.locale PublicBody.with_locale(locale) do found = PublicBody.find(:all, - :conditions => ["public_body_translations.url_name='#{name}'"], + :conditions => ["public_body_translations.url_name=?", name], :joins => :translations, :readonly => false) # If many bodies are found (usually because the url_name is the same across @@ -184,7 +186,7 @@ class PublicBody < ActiveRecord::Base end acts_as_versioned - self.non_versioned_columns << 'created_at' << 'updated_at' << 'first_letter' << 'api_key' + self.non_versioned_columns << 'created_at' << 'updated_at' << 'first_letter' << 'api_key' << 'info_requests_count' class Version attr_accessor :created_at @@ -549,9 +551,10 @@ class PublicBody < ActiveRecord::Base def notes_as_html self.notes end + def notes_without_html # assume notes are reasonably behaved HTML, so just use simple regexp on this - self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, "") + @notes_without_html ||= (self.notes.nil? ? '' : self.notes.gsub(/<\/?[^>]*>/, "")) end def json_for_api |