Problem with routes after scaffold

16 views
Skip to first unread message

IT Coobo Internal Team

unread,
Oct 31, 2012, 10:22:33 AM10/31/12
to rubyonra...@googlegroups.com
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!

--
Posted via http://www.ruby-forum.com/.

Luis Miguel Cabezas Granado

unread,
Oct 31, 2012, 10:38:49 AM10/31/12
to rubyonra...@googlegroups.com
Try this:

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

Enviado desde mi iPhone
> --
> 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 rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Colin Law

unread,
Oct 31, 2012, 11:03:18 AM10/31/12
to rubyonra...@googlegroups.com
On 31 October 2012 14:22, IT Coobo Internal Team <li...@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

IT Coobo Internal Team

unread,
Oct 31, 2012, 11:07:37 AM10/31/12
to rubyonra...@googlegroups.com
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.

Tommaso Visconti

unread,
Oct 31, 2012, 11:11:05 AM10/31/12
to rubyonra...@googlegroups.com
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-more-restful-actions

Tommaso Visconti

unread,
Oct 31, 2012, 11:13:16 AM10/31/12
to rubyonra...@googlegroups.com
Sorry, use a collection, not a member:


Cbapp::Application.routes.draw do
resources :users do
collection do

IT Coobo Internal Team

unread,
Oct 31, 2012, 12:36:05 PM10/31/12
to rubyonra...@googlegroups.com
thanks Tommaso and hazardco!

:)

both ways worked.


solved.
Reply all
Reply to author
Forward
0 new messages