REST perhaps I don't undestand it.

I find hard to work with rest and custom actions. I have an action

def logout   session[:user = nil end

for controller user. In my view I call <%= link_to "Logout', :action => 'logout'. When I click on link the error is:

Couldn't find Ruser with ID=logout

My routes.rb has resources :rusers. How I must call logout action?

you have a typo on your model name in controller.

There appear to be several typos:

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'

Couldn’t find Ruser with ID=logout

My routes.rb has resources :rusers.

the above means your user model has a diferent name than the one you are usign

Or should be session[:user] = nil Is that the same?

I think it is correct. Model is Ruser, resources :rusers is set by scaffold I have not set it.

Msan Msan wrote:

But....I have to set a route for every custom action that I add to controller?

Msan Msan wrote:

�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.

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.

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.

Hope that helps you.

So I've to do something like this?

class SessionsController < ApplicationController

  def destroy     session[:cas_user] = nil     session.delete(:casfilteruser)     CASClient::Frameworks::Rails::Filter.logout(self, rusers_url) end

end

and in html.erb page:

<%= link_to 'Logout', :controller => 'sessions', :action => 'destroy' %>

I think it is still not REST. I'm confused.

Msan Msan wrote: >>> > session[:user = nil

>> There appear to be several typos:

>> session[:user = nil >> should be: >> session[:user = nil] (missing ])

> Or should be session[:user] = nil > Is that the same?

No, Sandy was in error.

Marmen was correct. The missing ] belonged where he showed it. Sorry about any confusion.