session[:user = nil
should be:
session[:user = nil] (missing ])
<%= link_to "Logout’, :action => ‘logout’.
should be:
<%= link_to ‘Logout’, :action => ‘logout’ %> (inconsistent " and ’
around Logout; and missing %> )
My routes.rb has resources :rusers.
Try putting the following line into routes.rb:
map.connect ‘user/logout’, :controller => ‘user’, :action => ‘logout’
My routes.rb has resources :rusers.
Try putting the following line into routes.rb:
map.connect ‘user/logout’, :controller => ‘user’, :action => ‘logout’
But…I have to set a route for every custom action that I add to
controller?
Either that, or (not recommended really) you can enable the catch all
route in routes.rb by uncommenting the line towards the bottom that
looks like:
match ‘:controller(/:action(/:id(.:format)))’
but read the line above that, which tells you that if you do that,
you’ll enable access to all actions in all controllers; probably not
what you want to do.
On Sep 10, 2010, at 2:04 PM, Mauro wrote:
My routes.rb has resources :rusers.
Try putting the following line into routes.rb:
map.connect ‘user/logout’, :controller => ‘user’, :action => ‘logout’
This would be correct if you were on rails 2, but according to your
earlier post, you said you’ve got resources :rusers, which would only
work in rails3, I think. So, to add the custom route, do this:
match ‘/rusers/logout’ :to=>‘rusers#logout’
Go here and do some reading:
That should give you plenty to chew on and at least make the simple
routing stuff clear.
�My routes.rb has �resources :rusers.
�Try putting the following line into routes.rb:
�map.connect ‘user/logout’, :controller => ‘user’, :action => ‘logout’
But…I have to set a route for every custom action that I add to
controller?
Yes. . . and No.
If you insist on using a custom method in your controller then yes, you
will have to specify a route for it. However, you really should be
looking at things from the point of view of utilizing only the basic
crud actions of create, show, update and delete.
Consider what the verb logout implies. Logout from what? A session?
Then what are we actually doing with respect to a session? Deleting it?
Then perhaps the problem is that you really need another controller, say
user_sessions_controller, and that the delete action in that controller
is what should perform the logout action.
Keep in mind that in web applications speaking of logging in and out is
at best a very shaky metaphor and not a description of what is really
happening. One does not log on to a web application, one creates an
authenticated session. So long as that session persists then the
browser can consume the private resources provided by the web app. Once
the session is destroyed then the browser cannot consume those
resources.
In my opinion, this is the secret to thinking about REST, putting
everything in terms of the four basic verbs. If you are thinking in
terms of custom methods then you are probably not thinking REST.