diff --git a/app/models/party.rb b/app/models/party.rb index 6e52a5d..a988c27 100644 --- a/app/models/party.rb +++ b/app/models/party.rb @@ -62,6 +62,7 @@ class Party < ApplicationRecord has_many :favorites before_create :set_shortcode + before_save :set_edit_key ##### Amoeba configuration amoeba do @@ -100,6 +101,12 @@ class Party < ApplicationRecord self.shortcode = random_string end + def set_edit_key + if !self.user + self.edit_key = Digest::SHA1.hexdigest([Time.now, rand].join) + end + end + def random_string num_chars = 6 o = [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten