2017-11-03 5 views
2

업데이트 사용자 실패 경로 전달 오류가 어떻게 수정됩니까? 여기 Devise - 사용자 업데이트가 실패하여 사용자 지정 페이지로 리디렉션되는 경우

는 대체 유증 등록 업데이트 내 컨트롤러 코드 : 나는 변화를 시도

class RegistrationsController < Devise::RegistrationsController 

    def edit 
    render :edit 
    end 

    def update 
    self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) 
    prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email) 

    resource_updated = update_resource(resource, account_update_params) 
    yield resource if block_given? 
    if resource_updated 
     if is_flashing_format? 
     flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ? 
      :update_needs_confirmation : :updated 
     set_flash_message :notice, flash_key 
     end 
     bypass_sign_in resource, scope: resource_name 
     respond_with resource, location: after_update_path_for(resource) 
    else 
     clean_up_passwords resource 
     set_minimum_password_length 
     respond_with resource, location: profile_member_users_path(resource) 
    end 
    end 

    def after_update_path_for(resource) 
    profile_member_users_path(resource) 
    end 

end 

:

else 
    clean_up_passwords resource 
    set_minimum_password_length 
    respond_with resource 

else 
     clean_up_passwords resource 
     set_minimum_password_length 
     redirect_to profile_member_users_path(resource) 

로를하지만이에 errros을 고안 통과하지 보기.

+0

업데이트 코드는 그림이 아닌 텍스트로 보내주십시오. –

+0

원하는 동작을 명확히 할 수 있습니까? 정확히 당신이하고 싶은게 뭐야? –

+0

사용자 오류를 업데이트 할 때 사용자 지정 경로를 호출하십시오. 기본적으로 내 앱 호출 편집 등록보기는 devise가 만들었습니다. 다른 페이지로 리디렉션하고 싶습니다. 내 하찮은 영어 실력에 죄송하다는 말씀을 드리고 싶습니다. –

답변

0

리디렉션을 통해 오류를 수정해야합니까? 그럼 어떻게 그 오류를 사용 하느냐에 달려 있습니다. 고안은 그들을 해시로 resource.errors에 전달합니다. 방금 테스트했는데 이것이 귀하의 출발점이 될 수 있습니다.

else 
     clean_up_passwords resource 
     set_minimum_password_length 
     respond_with redirect_to: profile_member_users_path(resource), 
        notice: resource.errors['current_password'][0] 

    end 
+0

감사합니다. 이것은 나의 질문을 해결했다. 오류는 ressource.erros에 있습니다. –

+0

어두운면을 선택했습니다. 잘 했어 –

+0

왜? 나는 devise.erros없이 오류를 어떻게 사용 하는지를 몰랐다. 나는 단지 resource.errors를 사용할 필요가 있었다. –

0

리디렉션 중이므로 현재 리소스 데이터가보기로 전달되지 않습니다. 리디렉션없이보기를 렌더링해야합니다. 교체하십시오 :

redirect_to profile_member_users_path(resource) 

물론

respond_with resource, location: profile_member_users_path(resource) 

으로,이 원래 고안 코드 다르지 않다. 따라서 profile_member_users_path(resource)을 사용자 지정 경로로 바꿔야합니다.

+0

다른 위치 다음에 위치를 사용하려고하면 아무 것도 만들지 않습니다. 사용자 업데이트가 실패한 후 동일한 변경 경로 (편집)를 렌더링합니다. –

+0

원하는 작업을 수행 하시겠습니까? 당신이 원하는 행동을 말해 주면 도움이 될 수 있습니다. –