【发布时间】:2013-07-03 15:15:49
【问题描述】:
在我的小型 Rails 应用程序中,我有一个名为 say 的控制器,其中包含两页 hello 和 goodbye。我在应用程序中安装了设计。最初,我能够以 /users/sign_in 的身份访问 sing_in 页面,并且类似地进行注册。我无法退出,由于无法退出,我无法再次访问注册或登录页面。现在我在 eh say/hello 页面中输入了以下代码
<h1>Say#hello</h1>
<% if user_signed_in? %>
Hey signed in as <%= current_user.email %>.Not you?
<%= link_to "Logout", destroy_user_session_path %>
<% else %>
Hey <%= link_to "Login", new_user_session_path %> or Hey <%= link_to "Logup", new_user_registration_path %>
<% end %>
</p>
这是应用程序的路线页面。
Demo::Application.routes.draw do
devise_for :users
get "say/hello"
get "say/goodbye"
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
root :to => "say#hello"
end
每当我访问 say/hello 页面时,这就是我得到的输出
Links
Hey signed in as x@gmail.com.Not you? Logout
当我单击注销时。它说
No route matches [GET] "/users/sign_out"
当我直接访问 users/sign_in 时,我会被路由到 say/hello 页面。
我做错了什么?我应该如何退出?
我也试过了
destroy_user_session_path, :method => :delete
【问题讨论】:
-
尝试在你的路由文件中使用 devise_for :users, controllers: { sessions: 'sessions'} 代替 "devise_for :users"。 AND "DELETE"%> 在你的 html 中
-
是否显示相同的错误?您的应用程序中有会话控制器吗?
-
Demo::Application.routes.draw do devise_for :users, controllers: { sessions: 'sessions'} get "say/hello" get "say/goodbye" # 优先级是基于顺序的创建:首先创建 -> 最高优先级。 # 使用“rake routes”查看所有路由的布局。 # 您可以使用 "root" root :to => "say#hello" 路由站点的根目录
-
Ya bachan 在更改 routes.rb 和 html 文件后我得到了同样的错误
-
好的。现在,如果您的应用程序中没有会话控制器。只需从github.com/plataformatec/devise/blob/master/app/controllers/… 复制它并将其放入您的控制器中。然后将其第一行更改为“class SessionsController
标签: ruby-on-rails ruby-on-rails-3 devise