【问题标题】:Devise Redirect After Cancellation取消后设计重定向
【发布时间】:2015-08-19 09:05:29
【问题描述】:

我想在客户取消订阅后将其重定向到调查,但很难在重定向到调查的同时销毁会话。

organizations_controller.rb:

def cancel
    if @organization.subscription.cancel
      redirect_to "http://example.com/contact/cancel?organization=#{@organization.resource_id}"
    else
      flash[:error] = "An error has occurred."
      redirect_to settings_profile_path
    end
  end

如何使用设计destroy_user_session_path 并同时重定向到 suvery,而不会覆盖普通用户退出的重定向路径。当组织取消时,我只需要它来工作。

【问题讨论】:

  • 嗯,您可以手动取消会话设置或调用 logout_user 吗?
  • @argentum47 destroy_user_session_path 以上redirect_to 似乎不起作用...它重定向到调查;但是,用户仍然登录。如果我说redirect_to destroy_user_session_path && "http://example.com/contact/cancel?organization=#{@organization.resource_id}",它会注销用户,但不会重定向。这就像说你可以拥有一个,但不能拥有另一个。
  • 你在destroy_user_session_path(@user)中传递对象对吗?至少尝试 sign_out(@user) 然后

标签: ruby-on-rails ruby redirect devise


【解决方案1】:

sign_out_all_scopes(lock=true)(一个设计助手)替换destroy_user_session_path就可以了。

def cancel
    if @organization.subscription.cancel
      sign_out_all_scopes(lock=true)
      redirect_to "http://example.com/contact/cancel?organization=#{@organization.resource_id}"
    else
      flash[:error] = "An error has occurred."
      redirect_to settings_profile_path
    end
  end

【讨论】:

    【解决方案2】:

    我不太明白这个问题。您要销毁会话从而注销用户吗?如果是这样,试试这个:在你的应用程序控制器中添加这个私有方法

    def after_sign_out_path_for(user)
      if blah
        redirect_to :foo
      else
        redirect_to :bar        
      end
    end
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 2013-03-29
      • 2015-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      • 2011-08-15
      相关资源
      最近更新 更多