2017-11-03 14 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 
     redirect_to profile_member_users_path(resource) 

else 
    clean_up_passwords resource 
    set_minimum_password_length 
    respond_with resource 

をしかし、これはにerrrosを考案渡しません景色。

+0

あなたの更新コードは画像ではなくテキストとして投稿してください。 –

+0

希望する動作を明確にすることはできますか?あなたは何をしたいのですか? –

+0

ユーザーの障害を修正するときにカスタムパスを呼び出します。デフォルトでは、私のアプリケーションコール編集登録ビューはdeviseによって作成されました。私は別のページにリダイレクトしたい。私の悪い英語のために申し訳ありません。 –

答えて

0

リダイレクトでエラーを修正する必要がありますか?したがって、それらのエラーの使い方によって異なります。 Devisesはそれらをハッシュとして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

私は他の場所の後に場所を使用しようとすると、何もしません。ユーザーの更新が失敗した後、同じdeviseパスをレンダリングします(編集) –

+0

何をしたいですか?あなたが望む行動を教えてください。私が助けることができるかもしれません。 –

関連する問題