设计:注销*无需重定向?

Rub*_*tic 5 redirect render logout devise ruby-on-rails-3

我试图用设计登出,但没有重定向!因此,我想在注销后禁用重定向。原因是我想渲染一个特定的模板。 如何从设计中注销用户而无需重定向用户->仅此方法<-?我已经覆盖了设计会话控制器。

我的方法(从application_controller.rb中的before过滤器调用)

  def check_concurrent_session
    if user_signed_in?
      if current_user && !(session[:token] == current_user.login_token)
        render :template => "users/logout_duplex", :layout => "application", :locals => { sub_layout => "left" }
        # The next line always redirects to signout_path
        # I want to disable the complete redirect so it just logs out and shows the rendered template
        Devise.sign_out_all_scopes ? sign_out : sign_out(@user)
        return
      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

ush*_*sha 2

从 devise 继承会话控制器并拥有您自己的after_sign_out_path_for. 这就是设备在注销后用于重定向的方法。

class SessionsController < Devise::SessionsController

 protected
 def after_sign_out_path_for(resource)
  //your implementation
 end
end
Run Code Online (Sandbox Code Playgroud)

将其添加到您的 config/routes.rb

devise_for :users, :controllers => {:sessions => 'sessions'}
Run Code Online (Sandbox Code Playgroud)

该方法的设计实现如下所示

def after_sign_out_path_for(resource_or_scope)
 respond_to?(:root_path) ? root_path : "/"
end
Run Code Online (Sandbox Code Playgroud)

  • 使用我的示例中的行。Devise.sign_out_all_scopes ?Sign_out :sign_out(@user) *确实*使用 def after_sign_out_path 位置进行重定向,我不希望发生这种情况,这就是这个问题的原因 (3认同)