Phil
On Mon, Mar 28, 2011 at 4:52 PM, Peter Laurens <[email protected]> wrote: > Hi all, > > A relative newcomer to routes here - I have a controller on which I > would like to be able to specify only a couple RESTful operations (my > example is for a RESTful user sessions controller, where it only makes > sense to (1) create a session, and (2) destroy a session). > > Using 'resources' on a controller in the routes file gives all seven > methods so I'm not using that; I only need the two above, so my routes > file looks like this: > > match 'sessions' => 'sessions#create', :via => :put > match 'sessions' => 'sessions#destroy', :via => :delete > > Making a create route does not give you a route for 'new' -- you'll need to create both. You can also do: resources :sessions, :only => [:new, :create, :destroy] if you like. > Essentially I want a user to send a put (this is an idempotent > operation) to the sessions collection URL, with a params hash of > username and password. And calling delete on the same URL will log out > the session. > > However, my RSpec test, which looks like this: > > describe "PUT 'new'" do > # (NB this user is created in the 'before' method) > it "should be successful" do > put 'new', {:name => 'a_user_logging_in', :password => > 'a_password'} > response.should be_success > end > > it "should not be successful with a wrong username or password" do > put 'new', {:name => 'an_incorrect_user', :password => > 'a_password'} > response.should_not be_success > end > end > > > Does not pass as the routing fails! Here is the RSpec error: > > Failure/Error: put 'new', {:name => 'a_user_logging_in', :password => > 'a_password'} > ActionController::RoutingError: > No route matches {:name=>"a_user_logging_in", > :password=>"a_password", :controller=>"sessions", :action=>"new"} > > So clearly I've made an error here somewhere with my Routes, can someone > help me achieve what I'm after (i.e. just a put and delete on a > collection, which calls create and destroy on the controller?). > > Many many thanks for your kind help, > > - Nex > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

