RailsCasts Pro episodes are now free!

Learn more or hide this

Michael Grosser's Profile

GitHub User: grosser

Site: grosser.it

Comments by Michael Grosser

Avatar

You could use UrlStore https://github.com/grosser/url_store and just encode user id and expiration time inside the url, no new columns needed. Only drawback is that the token gets longer.

code = UrlStore.encode([user.id, 2.hours.from_now])
...
if id, expires = UrlStore.decode(params[:id])
  if expires > Time.zone.now
    ...