Rails 3 routes

24 views
Skip to first unread message

keerthi priya

unread,
Sep 25, 2012, 1:35:03 AM9/25/12
to rubyonra...@googlegroups.com
Hi all am learning rails 3.2.8 and i found that in routes if i have a controller called User and i have 5 def a, def b,def c and def d. do i need to mention routes to each def because in 2.3.8 you no need to mention routes for each def but when i come to 3.2.8 i have to mention routes for each def in a controller like
 match 'user/new' => 'user#new'
  match 'user/create' => 'user#create'
such way for each def in a controller. is there any other way to write a routes so that you no need to mention routes for each def.



Cheers,
Kp

KUL KING

unread,
Sep 25, 2012, 1:45:29 AM9/25/12
to rubyonra...@googlegroups.com
You can use the resources keyword.


--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Tf06HxXUXVgJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

keerthi priya

unread,
Sep 25, 2012, 3:27:21 AM9/25/12
to rubyonra...@googlegroups.com
any sample code plz

KUL KING

unread,
Sep 25, 2012, 3:37:52 AM9/25/12
to rubyonra...@googlegroups.com
You can use resources in following three different ways.

resources :users

All the methods in Users controller will have routes defined if you add above line in your routes.rb file. For example users controller have method #index then you will be able to open the url http://localhost:3000/users.

resources :users, :only => [:show, :new, :create]

If you use the above line in routes.rb then you will be able to just use the show, new and create actions of your controller.

resources :users, :except => [:index, :update, :destroy]

By using the above line you will be able to use any action in your controller execpt index, update and destroy.

keerthi priya

unread,
Sep 25, 2012, 6:51:47 AM9/25/12
to rubyonra...@googlegroups.com
Thank you very much Mr.King

KUL KING

unread,
Sep 25, 2012, 7:22:33 AM9/25/12
to rubyonra...@googlegroups.com
You are welcome. By the way does it solve your problem? As I am also a newbie in rails with 2-3 months experience.

Matt Jones

unread,
Sep 25, 2012, 8:41:28 AM9/25/12
to rubyonra...@googlegroups.com


On Tuesday, 25 September 2012 03:39:10 UTC-4, Kashif Umair Liaqat wrote:
You can use resources in following three different ways.

resources :users

All the methods in Users controller will have routes defined if you add above line in your routes.rb file. For example users controller have method #index then you will be able to open the url http://localhost:3000/users.

Not quite - only the 7 standard actions (new / create / show / index / edit / update / destroy) will be routed. You can write URLs that look like they go to other actions (/users/some_other_thing) but they'll actually be routed to the show action.
 
The Routing guide is a great reference for this stuff:


--Matt Jones

KUL KING

unread,
Sep 25, 2012, 8:45:12 AM9/25/12
to rubyonra...@googlegroups.com
OK. Thanks.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xk3HMCLrR38J.
Reply all
Reply to author
Forward
0 new messages