This is something I am using inside my model
This is the URL that gets posted to another 3rd party website through API
Post Model (post.rb)
"#{content.truncate(200)}...more http://domain.com/post/#{id.to_s}"
The "id" is referring to the post id. How can I convert that into a random 8 digit alphanumeric?
Right now, it gets displayed as something that people can alter http://domain.com/post/902
I want http://domain.com/post/9sd98asj
I know I probably need to use something like SecureRandom.urlsafe_base64(8)
but where and how can I set this up?
This is what I have in routes.rb
match '/post/:id', :to => 'posts#show', via: :get, as: :post
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…