3
我正在使用Devise進行身份驗證。我已登錄網站。登錄創建後用戶和公司。我如何銷燬當前會話併爲新創建的用戶創建新會話。已經登錄如何覆蓋用戶會話+ devise + rails
請看代碼。
----> sessions_controller.rb
class Users::SessionsController < Devise::SessionsController
# before_action :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
# end
end
---->的routes.rb
Rails.application.routes.draw do
devise_for :users, controllers: {
sessions: 'users/sessions'
}
root to: "companies#index"
resources :companies do
end
resources :company_users do
end
end
----> companies_controller
def create
@company = Company.new(company_params)
respond_to do |format|
if @company.save
format.html { redirect_to @company, notice: 'Company was successfully created.' }
format.json { render :show, status: :created, location: @company }
else
format.html { render :new }
format.json { render json: @company.errors, status: :unprocessable_entity }
end
end
end
我在這裏創建我的用戶和公司。完成後,我想爲這個新創建的用戶創建會話。
任何建議也歡迎以及請給出具體答案。非常感謝。
你可以更詳細說明你想重置會話或模擬用戶。 –
我找到了我的解決方案。正如我寫的,我想關閉當前用戶會話併爲新用戶創建一個新會話。 – wish