我正在尝试做的事情
如果他们没有登录,我想将用户发送到registrations#new 页面。
在您输入登录信息并单击提交后,我希望您被发送到registrations#show 页面。
怎么了
当您未登录时,它会将您发送到 registrations#new 页面(到目前为止正确)。但是当您提交登录表单时,它会通过重定向循环发送错误。服务器的输出就是这个块一遍又一遍地重复:
Started GET "/" for 127.0.0.1 at 2013-09-25 02:31:59 -0400
Processing by RegistrationsController#new as HTML
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 8 ORDER BY "users"."id" ASC LIMIT 1
Redirected to http://lvh.me:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.7ms)
我似乎无法弄清楚。它确实让您登录,正如我所看到的,通过手动导航到不同的页面,但authenticated
根路径无法正常工作。我在我的路线文件中尝试了几种不同的组合,但似乎无法得到它。我使用的代码是基于这个线程
我的代码
在我的应用程序控制器中,我有before_filter :authenticate_user!
我的路线文件:
devise_for :users, :controllers => {
:registrations => "registrations"
}
devise_scope :user do
root to: "registrations#new"
end
authenticated :user do
root to: "registrations#show", :as => "profile"
end
unauthenticated do
root to: "registrations#new", :as => "unauthenticated"
end