2011-11-03 1 views
18

ルートには"home#index"というルートパスがありますが、サインインまたはサインアップするときにafter_sign_up_path_forでそれを上書きしようとするとルートパスにリダイレクトされます。私はdevise subclassed controllerとapplication_controllerの両方に入れようとしましたが、うまくいきませんでした。ここで何をする必要がありますか?devys after_sign_up_path_forが無効になっています

class RegistrationsController < ApplicationController 
    def after_sign_up_path_for(resource) 
    show_cities_path(resource) 
    end 
end 

ルート

root :to => "home#index" 

答えて

65

Confirmableモジュールも有効にしている場合は、新しいサインアップが確認されるまで「sign-up」が無効になるので、after_inactive_sign_up_path_forを無効にする必要があります。 Confirmableがアクティブなときにafter_sign_up_path_forが呼び出されないようです。

+0

は私の課題であったこと、ありがとうございます。 – MicFin

+0

ありがとう! D – marman

+0

これは、ユーザーがログインに対して非アクティブなすべての場合に適用されることに注意してください。たとえば、 'active_for_authentication?をオーバーライドした場合などです。これは、ユーザーがアカウントを確認するまでログインしていない確認可能なケース。 –

6

:あなたは私がここにもこのことについてブログ

スキップされます「スーパー」文、後に何かを行う場合、登録コントローラ内

  1. は、内に、アクションを作成します実現するまでの問題私は、私がdeviseの登録コントローラを無効にしていると宣言するのを忘れていた。私の場合、私が考案し使用しています。ユーザーのリソースを、私はroutes.rbをにこれを追加しました:その後

    devise_for :users, :controllers => {:registrations => "registrations"} 
    

    を、私はafter_inactive_sign_up_path_forに指定されたリダイレクトが働いていました。

    Override devise registrations controllerには、このトピックに関するより完全な議論があり、上書きを宣言する別の方法があります。

11

私はゲームに遅れていますが、私はこの問題に遭遇し、解決策を見つけるのに苦労しました。

独自のRegistrationsControllerを使用してDeviseをカスタマイズする場合は、ApplicationControllerではなくそのコントローラにafter_sign_up_path_for(リソース)メソッドを追加する必要があります。 registrations_controller.rbで

private 

    def after_sign_up_path_for(resource) 
    new_page_path 
    end 

https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb

+0

OPの質問が別の回答によってうまく処理されている可能性がありますが、これは問題でした。 – lfzawacki

0

私はちょうどこの上で約2時間を吹きましたが、LiveReloadは私の問題でした。私はうまくリダイレ​​クトされましたが、LiveReloadはdevelopment.sqlliteの変更を受け取り、要求を無効にしていました。

0

実際、私たちは問題の解決のためにdeviseのソースコードを見ることができ、簡単です。コードが示すように

devise-3.4.1 $ vim app/controllers/devise/registrations_controller.rb

# POST /resource 
    def create 
    build_resource(sign_up_params) 

    resource_saved = resource.save 
    yield resource if block_given? 
    if resource_saved 
     if resource.active_for_authentication? 
     set_flash_message :notice, :signed_up if is_flashing_format? 
     sign_up(resource_name, resource) 
     respond_with resource, location: after_sign_up_path_for(resource) 
     else 
     set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format? 
     expire_data_after_sign_in! 
     respond_with resource, location: after_inactive_sign_up_path_for(resource) 
     end 
    else 
     clean_up_passwords resource 
     @validatable = devise_mapping.validatable? 
     if @validatable 
     @minimum_password_length = resource_class.password_length.min 
     end 
     respond_with resource 
    end 
    end 

 if resource.active_for_authentication? 
     ... 
     respond_with resource, location: after_sign_up_path_for(resource) 

     else 
     ... 
     respond_with resource, location: after_inactive_sign_up_path_for(resource)