daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def create_guest_user
  2.   u = User.new(:name => "guest", :email => "guest_#{Time.now.to_i}#{rand(100)}@example.com", guest: true)
  3.   u.save!(:validate => false)
  4.   cookies.signed.permanent[:guest_user_id] = u.id
  5.   u
  6. end
  7.    
  8. response.set_cookie(:guest_user_id, {
  9.   value: u.id,
  10.   path: '/',                 # cookie remains all pages in this domain
  11.   expires: 2.weeks.from_now, # cookie expires after 2 week
  12.   httponly: true,            # prevent javascript modify this cookie
  13. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top