2012-05-02 3 views
0

암호를 재설정 할 때 :레일 고안 - 업데이트에 대한 오류 나는이 컨트롤러 코드가

def update 

    super 
    respond_to do |format| 
     format.html{redirect_to session[:redirect_to]} 
    end 
    end 

내 클래스는 다음과 같이 유증 암호에서 상속 :

class Mobile::PasswordsController < Devise::PasswordsController 

나는이 오류가 :

AbstractController::DoubleRenderError in Mobile::PasswordsController#update 

    Render and/or redirect were called multiple times in this action. 
Please note that you may only call render OR redirect, and at most once per action. 
Also note that neither redirect nor render terminate execution of the action, so 
if you want to exit an action after redirecting, you need to do something like 
"redirect_to(...) and return". 

무엇을해야할까요? 리디렉션을 알고 있지만 올바른 방법을 모릅니다.

감사합니다.

답변

2

The update method의 Devise gem에는 이미 리디렉션이 있습니다. 그런 다음 리디렉션을 호출하면 오류가 발생합니다. 사용자 정의를 수행 할 경우이 같은 super 호출하지 않고 고안 메소드를 오버라이드 (override) 할 필요가 리디렉션 :

def update 
    self.resource = resource_class.reset_password_by_token(params[resource_name]) 

    if resource.errors.empty? 
     flash_message = resource.active_for_authentication? ? :updated : :updated_not_active 
     set_flash_message(:notice, flash_message) if is_navigational_format? 
     sign_in(resource_name, resource) 
     respond_with resource, :location => #your_path_on_success 
    else 
     flash[:error] = resource.errors.full_messages 
     redirect_to #your_path_on_failure 
    end 
    end 
+0

당신을 감사합니다. NoMethodError (정의되지 않은 메서드 인 nil : NilClass에 대해 정의 된 메서드 'active_agency_id') : app/controllers/welcome_controller.rb : 7 : 'show'에서 코드를 시도한 후에 이러한 오류가 발생했기 때문에 효과가 있었는지 알기 어렵습니다. – Awesomeness

+0

그런 종류의 오류를 수정하는 방법에 대한 의견이 있으십니까? 감사! – Awesomeness

+0

@ArcaneRaine 다음과 같이 보입니다 : unless current_user.active_agency_id.blank? && current_user.active_advertiser_id.blank? – Awesomeness