Forum: Ruby on Rails Problem with routes after scaffold

Dfca439caf59596c8359ade793c60766?d=identicon&s=25 IT Coobo Internal Team (urca)
on 2012-10-31 15:22
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!
D369616be7b74adb046219e44e95d61b?d=identicon&s=25 Luis miguel Cabezas granado (hazardco)
on 2012-10-31 15:40
(Received via mailing list)
Try this:

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

Enviado desde mi iPhone

El 31/10/2012, a las 15:22, IT Coobo Internal Team
<lists@ruby-forum.com> escribi:
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2012-10-31 16:04
(Received via mailing list)
On 31 October 2012 14:22, IT Coobo Internal Team <lists@ruby-forum.com>
wrote:
> Hi everbody,
>
> I'm new in the forum. I' studing ruby and rails and I hope learn faster
> with the help of the forum.

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
Dfca439caf59596c8359ade793c60766?d=identicon&s=25 IT Coobo Internal Team (urca)
on 2012-10-31 16:07
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.
6dbddfda34303f8d83620f7293612671?d=identicon&s=25 Tommaso Visconti (Guest)
on 2012-10-31 16:12
(Received via mailing list)
Il 31/10/12 15:22, IT Coobo Internal Team ha scritto:
> Cbapp::Application.routes.draw do
>    resources :users
>    root :to => 'users#index'
>    match 'users/login' => 'users#login'
> end

rules order in routes.rb is important: users resource 'users/:id'
matches before 'users/login' so login is the id :)
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-...
6dbddfda34303f8d83620f7293612671?d=identicon&s=25 Tommaso Visconti (Guest)
on 2012-10-31 16:14
(Received via mailing list)
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
Dfca439caf59596c8359ade793c60766?d=identicon&s=25 IT Coobo Internal Team (urca)
on 2012-10-31 17:36
thanks Tommaso and hazardco!

:)

both ways worked.


solved.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.