I’m using the Authlogic gem as the authentication system for a rails app. This is my code in the UserSessionsController
class UserSessionsController < ApplicationController
layout 'auth_layout'
def new
@user_session = UserSession.new
end
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Login successful!"
else
render :action => :new
end
end
def destroy
current_user_session.destroy
redirect_to new_user_session_url
end
end
Although every time I type in the address bar /user_sessions/destroy, I get the following error:
Unknown action
The action 'show' could not be found for UserSessionsController
Does anyone know how to resolve this? Thanks 🙂
Add the following to your
config/routes.rbAssuming you have your
user_sessionroutes defined as aresourcein yourconfig/routes.rb, thedestroyaction’s route requires the HTTP method beDELETEto/user_sessions, making aGETrequest to the (non-existent)/user_sessions/destroyroute through the address bar of your browser fail.The addition of the above route maps the
/user_sessions/destroypath you’re trying to access to load theUserSessionscontroller’sdestroymethod instead of the (non-existent)showmethod, passing"destroy"as the:idparam.