how to create a guest user in Rails 3 + Devise

前端 未结 3 1626
闹比i
闹比i 2021-01-31 23:22

currently I have a rails 3 app with devise. it requires the users to register / signin for access.

I would like to enable guest users. So that when a user visits certain

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 23:50

    After following the wiki, just replace calls to current_user with current_or_guest_user

    As far as views goes, do it in the controller with a before_filter.

    Without seeing any code from you it is hard to guess, but in pseudo-code it would be something like

    class ChatController < ApplicationController
     before_filter authenticate_user!, :except => [:join]  #this will force users to log in except for the join action
    
      def join
       chat_handle = current_or_guest_user.handle
       # some more code...
      end 
    

提交回复
热议问题