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
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:
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 开发者_JAVA技巧=> :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)
Removing resources :sessions
from the routes file should solve the problem.
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. Worked for me.
You don't have a root_url
defined. It is still pointing to the static public/index.html. (edited out by Ryan Bigg)
devise_for :users
is stated twice.
resources :users
is unnecessary unless you have a RESTful controller handling destroy and index actions outside of devise.
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
.
精彩评论