Allow anonymous/guest user to “try out” functionality without registering in Rails/Devise/CanCan app

前端 未结 2 2075
不知归路
不知归路 2021-02-06 14:08

I\'m developing a Rails 3 app using Devise and CanCan.

The app allows anonymous (not registered) users to access some of the app, and registered users to access other par

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-06 14:38

    I'm also working on a rails 3 project w/ devise and cancan. My needs are a little different in that I need to persist anonymous users' activity in the db (no need to sweep). Here's what I did to sign in the anonymous user. Hope this helps.

    def sign_in_anonymous_user
      unless user_signed_in?
        user = User.new
        role = "anonymous"
        user.confirmed_at = Time.now-1.minute
        user.save :validate => false
        sign_in :user, user
      end
    end
    

提交回复
热议问题