Tag: http status code 401

当用户打开多个窗口时,使用Devise在Rails中捕获401错误

场景是这样的:用户有2个窗口,他/她登录。他/她从一个登录,保持登录到另一个,然后在后者,触发一些动作,比如表单提交。 最初,发生的是它抛出了无效的真实性令牌错误。 我已经将protect_from_forgery中的protect_from_forgery更新为protect_from_forgery with: :null_session这样它就会抛出401而不是Exception。 大! 现在对于第2步,而不是用户只是看到一行文字说You need to sign in or sign up before continuing. ,我想将他/她重定向到登录页面。 这就是我遇到问题的地方……我一直在阅读本指南: http : //agileleague.com/blog/rails-3-2-custom-error-pages-the-exceptions_app-and-testing-with -capybara /表示401错误不是默认由rails捕获的。 该指南有两行代码,用于定义和捕获它,然后路由中的一行代码将使路由工作。 基本上它看起来像这样: # add to app/controllers/application_controller.rb class UnauthorizedException :unauthorized) # add to routes (in my case this is what I’ve done for Devise) devise_scope :user do match ‘/401’, to: ‘users/sessions#new’, type: “401”, […]

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

我正在重写Devise的失败响应,以便我可以设置401状态代码。 但是,当用户登录失败时,会将其重定向到“正在重定向”链接的页面。 如果我删除它:status => 401从重定向它工作正常。 class CustomFailure ‘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 编辑 或者,我想显示flash消息并保留在同一页面上,但添加以下代码行: render :text => “unauthorized”, :status => 401 让ruby抱怨: undefined method `render’ for # 这里发生了什么事?