環境: RAILS 3.2 + 認証用 DEVISE + Invitable + Confirmable アドオン。
Using devise (2.2.3)
Using devise-i18n (0.6.5)
Using devise_invitable (1.0.3)
ACCEPT (TO SIGN UP) 後に特定の場所にリダイレクトしようとしていafter_sign_in_path_for
ますが、SIGN IN と ACCEPT の後にのみ呼び出されるようです。
私は働くことができませんでしたafter_accept_path_for
。「サインイン後」の場所に引き続きリダイレクトされます。
コードはこちら
私のroutes.rbでは:
devise_for :users,
:controllers => { :registrations => 'registrations', :invitations => 'invitations' }
rake routes
私にこれをください:
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) registrations#cancel
user_registration POST /users(.:format) registrations#create
new_user_registration GET /users/sign_up(.:format) registrations#new
edit_user_registration GET /users/edit(.:format) registrations#edit
PUT /users(.:format) registrations#update
DELETE /users(.:format) registrations#destroy
user_confirmation POST /users/confirmation(.:format) devise/confirmations#create
new_user_confirmation GET /users/confirmation/new(.:format) devise/confirmations#new
GET /users/confirmation(.:format) devise/confirmations#show
accept_user_invitation GET /users/invitation/accept(.:format) devise/invitations#edit
user_invitation POST /users/invitation(.:format) devise/invitations#create
new_user_invitation GET /users/invitation/new(.:format) devise/invitations#new
PUT /users/invitation(.:format) devise/invitations#update
私の登録コントローラーで:
class RegistrationsController < Devise::RegistrationsController
# clear session
def create
super
session[:omniauth] = nil unless @user.new_record?
end
#protected
# after_sign_up_path_for doesn't seem to be called when using Confirmable module
# def after_inactive_sign_up_path_for(resource)
# #me_path
# session[:user_return_to].nil? ? me_path : session[:user_return_to]
# end
private
def build_resource(*args)
super
if session[:omniauth]
@user.apply_omniauth(session[:omniauth])
@user.valid?
end
end
end
また
class Users::InvitationsController < Devise::InvitationsController
protected
def after_accept_path_for
session[:user_return_to].nil? ? me_path : session[:user_return_to]
end
end
私のアプリケーションコントローラーでは、(私はそれを機能させようとしたいくつかのコメント付きコードを意図的に残しました):
def store_location
session[:user_return_to] = request.fullpath
end
# def after_sign_up_path_for
# me_path
# end
#
# def after_inactive_sign_up_path_for(resource)
# me_path
# #session[:user_return_to].nil? ? me_path : session[:user_return_to]
# end
# https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-on-successful-sign-up-(registration)
def after_sign_in_path_for(resource)
me_path
#dashboard_path
#session[:user_return_to].nil? ? dashboard_path : session[:user_return_to]
end
助言がありますか?
デバッグ用リダイレクトの追加
これを私のapplication_controllerに追加します
def redirect_to_with_logging(*args)
logger.debug "Redirect: #{args.inspect} from #{caller[0]}"
redirect_to_without_logging *args
end
alias_method_chain :redirect_to, :logging
サインイン後、魅力のように機能します
Started POST "/users/sign_in" for 127.0.0.1 at 2013-04-25 14:20:04 +0200
Processing by Devise::SessionsController#create as HTML
[... I removed some of the Session creation info ...]
Redirect: ["/dashboard"] from /Users/joel/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.11/lib/action_controller/metal/responder.rb:135:in `redirect_to'
Redirected to http://localhost:3000/dashboard
Completed 302 Found in 968ms (ActiveRecord: 0.0ms)
ドキュメント:
承認後 <====