== Tutorial Injection #1 == Normally I would just pass some links but at times it's a little refreshing to add some very simple tutorials that many people ask about. This tutorial is about RESTful routing and mapping resources.
=== RESTful Routing and Mapping Resources (advanced) === By default, whenever you create a scaffold, 7 methods are automatically created for you. These are index, new, edit, show, update, create, and destroy. In order to map all paths to these resources a simple map resources line is automatically created for you in your routes.rb file using the pluralized name of the controller. E.g. scaffold name product produces a controller called products map.resources :products This one little line now maps all of your RESTful resources for this controller. However, what if you had something like this? E.g. scaffold name users_allowed produces a controller called users_alloweds Now you wouldn't want people to see http://yourdomain.com/users_alloweds would you? That would look very strange or peculiar. So, you can do something as simple as this: map.resources :users_alloweds, :as => 'users_allowed' Now your url will look like http://yourdomain.com/users_allowed which is a little better. But, what if you want to group certain resources by a particular category. Say for instance you want to group this particular url in a category called members. Well, you can use a nifty prefix command: map.resources :users_alloweds, :as => 'users_allowed', :path_prefix => 'members' Now your url will look like http://yourdomain.com/members/users_allowed which gives you a nice category grouping and a singular path name. And, lastly, for this very simple tutorial, what if you wanted to take this further and just allow only the index method/view to be accessed and the rest of the resources not. A simple way: map.resources :users_alloweds, :as => 'users_allowed', :only => 'index', :path_prefix => 'members' (acceptable) http://yourdomain.com/members/users_allowed/ (not allowed) http://yourdomain.com/members/users_allowed/*anything ==================================== If you need to understand more about routing, please visit: http://guides.rubyonrails.org/routing.html -- 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 rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---