【问题标题】:Filter chain halted as :require_no_authentication rendered or redirected过滤器链因 :require_no_authentication 呈现或重定向而停止
【发布时间】:2016-02-25 22:29:48
【问题描述】:

我使用了 devise gem 并使用以 User 为名称的 devise 命令生成了视图。

为了在整个应用程序中显示登录/注销链接,我将其添加到我的 layouts/application.html.erb

<% if user_session.present? %>
  <%= link_to "logout", destroy_user_session_path, :method => 'delete' %>
<% else %>
  <%= link_to "Login", new_user_session_path, :method => 'get' %>
<% end %>
<%= yield %>

这是只有索引操作的主控制器:

class HomeController < ApplicationController   
  def index

  end 
end

根被定义为指向home#index

当我启动应用程序时,它显示登录链接,点击该链接后,我收到以下错误:

Started GET "/users/sign_in" for ::1 at 2015-11-23 23:15:32 +0530
Processing by Devise::SessionsController#new as HTML
  User Load (0.3ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 10ms (ActiveRecord: 0.3ms)


Started GET "/" for ::1 at 2015-11-23 23:15:32 +0530
Processing by HomeController#index as HTML
  Rendered home/index.html.erb within layouts/application (0.1ms)
  User Load (0.4ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
Completed 200 OK in 8ms (Views: 6.7ms | ActiveRecord: 0.4ms)

请建议我哪里出错了。我无法找出错误。

【问题讨论】:

    标签: ruby-on-rails ruby devise


    【解决方案1】:

    对于HomeController,您可能需要skip_before_filter。在顶部HomeController:skip_before_filter :require_no_authentication, only: [:index]

    我不确定一起跳过过滤器是正确的解决方案。如果这对您不起作用,this post 可能会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-11
      • 2018-10-08
      • 1970-01-01
      • 1970-01-01
      • 2012-09-19
      • 2015-06-30
      • 1970-01-01
      相关资源
      最近更新 更多