Guest User

Untitled

a guest
Jan 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  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. })
Add Comment
Please, Sign In to add comment