[英]Rails devise help routing error No route matches “/sessions/user”
When I login on my page I automatic go to the route: http://localhost:3000/sessions/user 当我在我的页面上登录时,我自动转到路线: http:// localhost:3000 / sessions / user
And I get this error: 我收到这个错误:
Routing Error
No route matches "/sessions/user"
I have created a controller named sessions_controller.rb in users folder here it is: 我在users文件夹中创建了一个名为sessions_controller.rb的控制器,它是:
class Users::SessionsController < Devise::SessionsController
def new
redirect_to root_url, :notice => "You have been logged out."
end
def create
user = User.authenticate(params[:login], params[:encrypted_password])
if user
session[:user_id] = user.id
redirect_to root_url, :notice => "Logged in successfully."
else
flash.now[:alert] = "Invalid login or password."
render :action => 'new'
end
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "You have been logged out."
end
end
My route file: 我的路线档案:
Densidste::Application.routes.draw do
match 'user/edit' => 'users#edit', :as => :edit_current_user
devise_for :users, :controllers => { :sessions => "users/sessions" } do
get "login", :to => "devise/sessions#new"
get "opret", :to => 'users/users#new'
get "logud", :to => 'users/users#destroy'
end
resources :sessions
resources :users
devise_for :users, :controllers => { :sessions => "users/sessions" }
resources :aktivs
resources :taggingposts
resources :tags
resources :kommentares
resources :posts
end
(Old question but I ran into the same issue when setting up Devise, so hope this helps others) (老问题,但我在设置Devise时遇到了同样的问题,所以希望这有助于其他人)
Removing resources :sessions
from the routes file should solve the problem. 删除resources :sessions
路由文件中的resources :sessions
应该可以解决问题。
For those who experiencing this issue with Devise 2.0
and Rails 3.2.1
and checked all the observations made by @Micah Alcorn but still facing the problem — restart your web server . 对于那些使用Devise 2.0
和Rails 3.2.1
遇到此问题的人,并检查了@Micah Alcorn所做的所有观察但仍然面临问题 - 重新启动您的Web服务器 。 Worked for me. 为我工作。
You don't have a root_url
defined. 您没有定义root_url
。 It is still pointing to the static public/index.html. 它仍然指向静态public / index.html。 (edited out by Ryan Bigg) (Ryan Bigg编辑)
devise_for :users
is stated twice. devise_for :users
说两次。
resources :users
is unnecessary unless you have a RESTful controller handling destroy and index actions outside of devise. resources :users
除非您有一个RESTful控制器处理devise之外的destroy和index操作,否则resources :users
是不必要的。
Do you, in fact, have a "users" controller for that first edit action too? 事实上,你是否也有第一个编辑动作的“用户”控制器? That should probably be in a custom Users::RegistrationsController < Devise::RegistrationsController
. 这应该是在自定义Users::RegistrationsController < Devise::RegistrationsController
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.