使用设计gem过滤链停止错误

时间:2014-02-19 04:48:48

标签: ruby-on-rails ruby ruby-on-rails-3 devise

我正在使用带有rails的设计。我已经在设计中生成了用户模型,我没有用户控制器和家庭控制器。我的根页是devise/sessions#new

我的根路径

 devise_scope :user do
   root :to => "users/sessions#new"
 end
 devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :registrations => "users/registrations" }

当我运行localhost:3000时,我收到以下错误。

Filter chain halted as :require_no_authentication rendered or redirected. 

Started GET "/" for 127.0.0.1 at 2014-02-19 10:07:46 +0530
Processing by Devise::SessionsController#new as HTML
  User Load (0.2ms)  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 3ms (ActiveRecord: 0.2ms)

我在互联网上找到的解决方案是在会话控制器prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]中添加它。我怀疑的是如何访问会话控制器。它不是在控制器中生成的,它是内置模块,还是有其他方法可以解决这个问题。

应用/控制器/用户/ session_controller.rb

class Users::SessionsController < Devise::SessionsController
  prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
end

1 个答案:

答案 0 :(得分:4)

您可以像这样覆盖会话控制器:

<强> route.rb

devise_scope :user do
  root to: "users/sessions#new"
end

应用/控制器/用户/ sessions_controller.rb

class Users::SessionsController < Devise::SessionsController
  prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
end