Rails Devise - current_user is nil

后端 未结 4 1212
甜味超标
甜味超标 2021-01-02 00:27

For some reason, current_user returns nil in my model-less controller (Subscriptions). I have found nothing on the Internet to justif

4条回答
  •  半阙折子戏
    2021-01-02 01:25

    for current_user to work you need to add before_filter :authenticate_user! to your class, like:

    class SubscriptionsController < ApplicationController  
      before_filter :authenticate_user!
    
      def new
        ...
      end
    
      def create
        curent_user    # returns nil
      end
    end
    

    and the authenticate_user! method will set the current user for you :)

提交回复
热议问题