2012-05-02 12 views
0

をリセットするとき、私は、このコントローラのコードを持っている:Railsは工夫 - アップデートのエラーパスワード

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コールせずに考案メソッドをオーバーライドする必要がリダイレクト:

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