【问题标题】:Rack Warden: how can I access the message passed to the fail! method?Rack Warden:我如何访问传递给失败的消息!方法?
【发布时间】:2012-04-07 17:38:45
【问题描述】:

当 Warden 中的身份验证策略失败时,可以将消息传递给 fail! 方法。如何在我的默认失败应用程序操作中访问此消息,以便我可以将其显示在 Flash 消息中?我试过request.env['warden'].message,但在查看Warden::Proxy 的代码后,这个变量只为获胜策略设置。想法?

【问题讨论】:

    标签: rack warden


    【解决方案1】:

    当使用失败或失败!方法,您可以从环境守望者对象中获取失败消息。

    例子:

    def unauthenticated
      flash[:alert] = env["warden"].message unless env["warden"].message.blank?
    end
    

    http://www.rubydoc.info/github/hassox/warden/Warden/Proxy#message-instance_method

    【讨论】:

      【解决方案2】:

      也许另一种失败策略的方式(来自最近的文档)是使用throw(:warden, :foo => 'bar')。您抛出的任何内容都将通过request.env['warden.options'] 在您的失败应用程序中可用,包括所需网址的字符串。高温

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-28
        • 2013-09-29
        • 2015-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多