Problem with routes after scaffold

Hi everbody,

I'm new in the forum. I' studing ruby and rails and I hope learn faster
with the help of the forum.

Well, my problem is basic. I have made a scaffold to create a new object
User. User has name, email and password.

I created a new view named "login", but i don't know how to make the
route to this view. I Have the function in the controller too.

Cbapp::Application.routes.draw do
  resources :users
  root :to => 'users#index'
  match 'users/login' => 'users#login'
end

and I got this error: Couldn't find User with id=login

Thanks!

Try this:

I suggest your best plan might be to work right through a tutorial on
rails to help you to understand the basics. railstutorial.org is good
and is free to use online. Make sure that any tutorial you use is for
Rails 3 and that you use exactly the right version of rails that the
tutorial expects.

Colin

WOW! I don't believe it. I only have to reorder the lines as hazardco
said!

SOLVED! but i have a question. Why reorder the lines solved my problem?

anyway thanks guy.

rules order in routes.rb is important: users resource 'users/:id' matches before 'users/login' so login is the id :slight_smile:
you can invert the order of the rules or, better, use a member:

Cbapp::Application.routes.draw do
   resources :users do
     member do
       get 'login'
     end
   end
   root :to => 'users#index'
end

Take a look here: http://guides.rubyonrails.org/routing.html#adding-more-restful-actions

Sorry, use a collection, not a member:

Cbapp::Application.routes.draw do
   resources :users do
     collection do
       get 'login'
     end
   end
   root :to => 'users#index'
end

thanks Tommaso and hazardco!

:slight_smile:

both ways worked.

solved.