Save edit key for parties with no user ID
This commit is contained in:
parent
cce33ebf08
commit
e45dabf39a
1 changed files with 7 additions and 0 deletions
|
|
@ -62,6 +62,7 @@ class Party < ApplicationRecord
|
||||||
has_many :favorites
|
has_many :favorites
|
||||||
|
|
||||||
before_create :set_shortcode
|
before_create :set_shortcode
|
||||||
|
before_save :set_edit_key
|
||||||
|
|
||||||
##### Amoeba configuration
|
##### Amoeba configuration
|
||||||
amoeba do
|
amoeba do
|
||||||
|
|
@ -100,6 +101,12 @@ class Party < ApplicationRecord
|
||||||
self.shortcode = random_string
|
self.shortcode = random_string
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_edit_key
|
||||||
|
if !self.user
|
||||||
|
self.edit_key = Digest::SHA1.hexdigest([Time.now, rand].join)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def random_string
|
def random_string
|
||||||
num_chars = 6
|
num_chars = 6
|
||||||
o = [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten
|
o = [('a'..'z'), ('A'..'Z'), (0..9)].map(&:to_a).flatten
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue