Skip to content

Commit ec42a53

Browse files
committed
fixing issue where public_id is lost on porting
1 parent 0167af0 commit ec42a53

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

app/models/protip.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class Protip < ActiveRecord::Base
1919

2020
scope :random, ->(count=1) { order("RANDOM()").limit(count) }
2121
scope :recently_created, ->(count=5) { order(created_at: :desc).limit(count)}
22-
scope :recently_most_viewed, ->{ order(views_count: :desc).where(public_id: %w{ewk0mq kvzbpa vsdrug os6woq w7npmq _kakfa}) }
22+
scope :recently_most_viewed, ->{ order(views_count: :desc).where(
23+
public_id: %w{ewk0mq kvzbpa vsdrug os6woq w7npmq _kakfa})
24+
}
2325

2426
def to_param
2527
self.public_id
@@ -81,6 +83,7 @@ def cacluate_score
8183
end
8284

8385
def generate_public_id
86+
return self.public_id if self.public_id
8487
self.public_id = SecureRandom.urlsafe_base64(4).downcase
8588
#retry if not unique
8689
generate_public_id unless Protip.where(public_id: self.public_id).blank?

0 commit comments

Comments
 (0)