aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Houston <robin.houston@gmail.com>2012-06-06 13:27:38 +0100
committerRobin Houston <robin.houston@gmail.com>2012-06-06 19:35:12 +0100
commit24b110837a5e7e92f0dfcc5a0e0dfc53b9f84b29 (patch)
tree6373e2308c48b5985eadf6f444e8ecc8f2cc56b2
parent0df32aab05e15589a237b59219073d80a9db3d6c (diff)
Initialise API key in the model
-rw-r--r--app/models/public_body.rb8
1 files changed, 6 insertions, 2 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 5f89878ef..a372de435 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -29,6 +29,7 @@
# $Id: public_body.rb,v 1.160 2009-10-02 22:56:35 francis Exp $
require 'csv'
+require 'securerandom'
require 'set'
class PublicBody < ActiveRecord::Base
@@ -88,10 +89,13 @@ class PublicBody < ActiveRecord::Base
end
end
- # Make sure publication_scheme gets the correct default value.
- # (This would work automatically, were publication_scheme not a translated attribute)
def after_initialize
+ # 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?
+
+ # Set an API key if there isn’t one
+ self.api_key = SecureRandom.base64(32) if self.api_key.nil?
end
# like find_by_url_name but also search historic url_name if none found