I'm having a problem getting the logout to work correct.
The sessions controller is how one logs in and out:
Here is the destroy action:
def destroy
self.current_user.forget_me if logged_in?
cookies.delete :auth_token
reset_session
flash[:notice] = "You have been logged out."
redirect_to('index/welcome')
end
Just to preface, on my home page if user is logged in it displays the
user name. The cookies and sessions are working correctly. However
I've tried to get the logouts 2 ways:
One is by creating a link_to 'sessions/destroy' This seems to do
nothing , but return an error:
Unknown action
No action responded to show
The other way is that I just link to sessions which gives me an
nil.login error for this view:
<%= current_user.login %>
<%= current_user.created_at.strftime("%m/%d/%Y") %>
I'd expect it being REST , that I need the link to show something like
/destroy;6
I was concerned initially that I would need to identify the session that it will destroy. Then I realised there is no model for the session to identify with an id.
Instead the sessions controller is just an interface to the session itself. In the destroy method, all actions taken are in relation to the current session only so nothing is actually being affected in the db.
A link to session_url with the method :delete causes the routes to map this to the destroy method.
This is seriously taking some getting used to for me.
Thanks for the information Daniel. Running the link removes the token
and session. However I'm getting this error
Routing Error
no route found to match "/welcome" with {:method=>:get}
So the routes are set up correctly as you stated above and have been.
However my main page is is the index / welcome (action)
And in the destroy method I configured the blank redirect_to
redirect_to('index/welcome')
So I think it was just set to default, perhaps I should have left it
at that ? Gonna try it.