2016-11-29 54 views
1

我想做一些訪客用戶功能。創建用戶後,我正在強制登錄。用戶登錄成功並且current_user可用相同的方法。但在此之後,當我重定向到其他控制器時,我丟失了current_user。設計強制登錄用戶去註銷automaitcaly

class Notloggedin::AccountRequestsController < Notloggedin::BaseController 
    def create 
    params[:account_request][:user_attributes][:email] = params[:account_request][:contact_email] 
    params[:account_request][:user_attributes][:first_name] = params[:account_request][:contact_name] 
    params[:account_request][:user_attributes][:guest] = true 
    user = User.where(email: params[:account_request][:contact_email], guest: false) 
    @account_request = AccountRequest.new(permitted_account_request_params) 
    if user.empty? && @account_request.user.skip_confirmation! && @account_request.office.save && @account_request.save 
     @account_request.user.administrated_offices << @account_request.office 
     sign_in(:user, @account_request.user) 
     redirect_to edit_dentistry_path(@account_request.office.slug, step: 3) 
    else 
     if user.present? 
     flash[:alert] = 'You already have account with this email please login and create clinic from admin section.' 
     else 
     flash[:alert] = "#{@account_request.office.errors.full_messages.join(', ')} #{@account_request.errors.full_messages.join(', ')}" 
     end 
     redirect_to request.referrer 
    end 
    end 

    private 

    def permitted_account_request_params 
    params.require(:account_request).permit! 
    end 
end 

回答

1

這一定是這個原因,如果你的用戶是無效的,這意味着任何驗證失敗,請檢查您的用戶對

user.saveuser.valid?user.errors

嘗試這些,你會看到背後的問題這,這不是在設計它的理解問題的錯誤:)