I am using authlogic for my application’s authentication. If I decide
to login with an account and then immediately logout, I get an error.
Unknown action
The action ‘show’ could not be found for UserSessionsController
The server log in development says:
Started GET “/user_session” for 127.0.0.1 at Sun Nov 07 13:28:31 -0800
2010
AbstractController::ActionNotFound (The action ‘show’ could not be found
for UserSessionsController):
Rendered
/usr/lib/ruby/gems/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb
within rescues/layout (0.9ms)
Now if I login and then click on some other links within the application
and then logout, the logout function works as it should.
user_sessions controller
class UserSessionsController < ApplicationController
before_filter :require_no_user, :only => [:new, :create]
before_filter :require_user, :only => :destroy
def new
@user_session = UserSession.new
end
def create
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Login successful!"
redirect_to :controller => "list"
else
render :action => :new
end
end
def destroy
current_user_session.destroy
flash[:notice] = "Logout complete. Have a nice day!"
redirect_to root_url
end
end
application layout file snippet
<% if current_user %>
<li><a><%= link_to current_user.login, edit_user_path(:current)
%></a></li>
<li><%= link_to "logout", user_session_path, :method => :delete %></li>
<% else %>
<li><%= link_to "log In", new_user_session_path %></li>
<% end %>