[英]Devise register and login rails
默認情況下帶有devise。 用戶注冊后,它會在注冊后自動登錄。 無論如何,是否有注冊用戶而不自動登錄並重定向到登錄頁面的信息?
您需要重寫Devise::RegistrationsController#create
。 您可以在這里查看注冊的工作方式
首先,創建Devise :: RegistrationsController的自定義控制器子類
class RegistrationController < Devise::RegistrationsController
def create
build_resource(sign_up_params)
resource.save
yield resource if block_given?
if resource.persisted?
if resource.active_for_authentication?
set_flash_message! :notice, :signed_up
respond_with resource, location: root_path # Change this to whatever route your want
else
set_flash_message! :notice, :"signed_up_but_#{resource.inactive_message}"
expire_data_after_sign_in!
respond_with resource, location: after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
set_minimum_password_length
respond_with resource
end
end
end
然后告訴devise使用自定義控制器:
devise_for :users, :controllers => {:registrations => "registrations"}
假設User
是當然的模型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.