相关疑难解决方法(0)

Ruby-on-Rails:如何摆脱"你被重定向"页面

我正在重写Devise的失败响应,以便我可以设置401状态代码.但是,当用户登录失败时,会将其重定向到"正在重定向"链接的页面.如果我:status => 401从重定向中删除它,它可以正常工作.

class CustomFailure < Devise::FailureApp
    def redirect_url
      new_user_session_url(:subdomain => 'secure')
    end

    def respond
        if http_auth?
           http_auth
        else
           store_location!
           flash[:alert] = i18n_message unless flash[:notice]
           redirect_to redirect_url, :status => 401
        end
    end
end
Run Code Online (Sandbox Code Playgroud)

编辑

或者,我想显示flash消息并保留在同一页面上,但添加以下代码行:

render :text => "unauthorized", :status => 401
Run Code Online (Sandbox Code Playgroud)

让红宝石抱怨:

undefined method `render' for #<CustomFailure:0x00000103367f28>
Run Code Online (Sandbox Code Playgroud)

这里发生了什么事?

redirect ruby-on-rails http-status-codes devise http-status-code-401

18
推荐指数
1
解决办法
9797
查看次数