Deviseの認証後のリダイレクト

Railsの便利な認証プラグイン「Devise」は、ログイン後に、user_root、rootの順にリダイレクトを試みるけど、これらのnamed routesを、

# redirect when logged-in.
namespace :user do
  root :to => user_show_path(current_user)
end

のように、ログイン後にセットされる値を使って定義することはできない。routes.rbは初期化時に読まれて各種ルートが設定されるから。

なので、

 class ApplicationController < ActionController::Base
   protect_from_forgery
+
+  def sign_in_and_redirect(resource_or_scope, resource=nil)
+    redirect_to user_hogehoge_path(current_user)
+  end
 end

のように、「Devise::Controllers::Helpers#sign_in_and_redirect」をオーバーライドしてみた。