2014-02-19 16 views
2

我正在使用與軌的設計。我已經在設計中生成用戶模型,並且我沒有用戶控制器和主控制器。我的根頁面是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" } 
當我運行本地主機

: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 
+0

看看https://github.com/plataformatec/devise#configuring-controllers –

+0

@ IshankGupta-這不是我的預期。當我運行localhost:3000時,它不會重定向到我的根路徑。當我想通過omniauth回調登錄時,它不會返回到正確的路徑。說太多的重定向。 http:// localhost:3000 /中的網頁導致了太多的重定向。 – Sam

回答

4

您可以覆蓋這樣的會話控制器:

route.rb

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

應用程序/控制器/users/sessions_controller.rb

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

@ vanda-我再次得到同樣的錯誤。我已更新我已完成的工作 – Sam

+3

@Jeff發生這種情況是因爲您已經登錄。使用'skip_before_filter'而不是'prepend_before_filter'查看[this](http://stackoverflow.com/questions/9631432/rails3-devise-signup -filter-chain-halted-as-require-no-authentication-rendered)和[this](https://github.com/plataformatec/devise/issues/974) –

+0

我發現了真正的錯誤。在根路徑中,我不應該註冊路徑。我需要提一些其他的路徑 – Sam