2017-10-21 8 views
0

레일에 유증 이메일 확인 후 사용자 sign_in하는 방법 "귀하의 이메일 주소는 성공적으로 확인되었습니다." 사용자에게는 로그인하지 마십시오. 내 확인 컨트롤러 및 경로 에이 코드를 작성했습니다내가 이메일 확인 후 사용자 로그인의 자동차에 지난 7 시간에서 노력하고 있지만이 확인 링크를 클릭하면 다음 그것을 말한다

devise_for :users, controllers: {confirmations: 'users/confirmations'} 

class ConfirmationsController < Devise::ConfirmationsController 
    #private 
    def after_confirmation_path_for(resource_name, resource) 
    sign_in(resource) 
    render plain: "here" 
    redirect_to "/admins/view_account", notice: "User deleted." 
    end 
end 

도움이 감사 매우 감사드립니다.

+0

처럼처럼

노선해야 하는가? – gates

+0

@gates 예 확인 확인 컨트롤러에 들어가고 있습니다 – john

+0

@gates ??? 당신의 제안은 무엇입니까? – john

답변

1

전자 메일 확인 후 자동으로 로그인하면 Devits의 기본 동작으로 사용되며 이후 herehere과 같이 보안 조치로 인해 변경되었습니다 (3.1 이후).

여전히 고안의 버전에 따라, 그것을 프로젝트 내에서 config/initializers/devise.rb 파일에 아래 라인을 설정할 수 있는지 확인하려면

:

config.allow_insecure_sign_in_after_confirmation=true 

것은 당신이 최신 고안 버전을 사용하는 경우, 당신은 할 수 있습니다

class Users::ConfirmationsController < Devise::ConfirmationsController 
    def show 
    super do |resource| 
     sign_in(resource) if resource.errors.empty? 
    end 
    end 
end 
: 대신 그에게, 당신이 ( 네임 스페이스를 마음과 경로를 언급 해주십시오) 컨트롤러 코드 위에서 언급 한 내용의 대체 app/controllers/users/confirmations_controller.rb에이 코드를 사용하여 기본 컨트롤러를 확장

지 확인하십시오 당신이 질문의 시작 부분에 붙여 넣은 코드는 config/routes.rb에 속하는 :

devise_for :users, controllers: { confirmations: 'users/confirmations' } 

는 희망이 도움이!

0

는 내가 직접 해결했다. "여기"이

devise_for :users, controllers: {confirmations: 'confirmations'} do 
    #put "confirm_user", to: "confirmations#confirm_user" 
    get "confirmation", to: "confirmations#after_confirmation_path_for" 
    end 

컨트롤러가 왜 일반 렌더링 한 않는이

class ConfirmationsController < Devise::ConfirmationsController 
    #private 
    def after_confirmation_path_for(resource_name, resource) 
    sign_in(resource) 
    #render plain: "here" 
    #redirect_to "/admins/" 
    end 

    def show 
    self.resource = resource_class.confirm_by_token(params[:confirmation_token]) 

    if resource.errors.empty? 
     set_flash_message(:notice, :confirmed) if is_flashing_format? 
     sign_in(resource) # <= THIS LINE ADDED 
     redirect_to "/your path/" 
    else 
     respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new } 
    end 
    end 


end