Hi, Can anyone please explain me why we need routes.rb also explain the basic idea abt routes.rb file. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MikeG1-F66HEGuBJ/9Wk0Htik3J/w@public.gmane.org
2008-Sep-05 14:30 UTC
Re: Why we need routes.rb
Take a look at http://github.com/lifo/docrails/tree/master/railties/doc/guides/routing/routing_outside_in.txt --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
routes.rb is the logical entry point of your application (the real entry point is dispatch.rb, but that''s another story). This file defines a map of URL templates and controller/actions to be executed. How do your application knows that http://mysite.com/ticket should go to the Booking controller and run the show_tickets action? You define a map on your routes.rb file. (in this example: map.connect "ticket", :controller => "Booking", :action => "show_tickets") The URL fits the template "ticket"(the parameter just after map.connect). This tells rails that when the URI /tickets fits the pattern, it should instantiate the Booking controller and execute the show tickets action. At the very bottom of your routes.rb file is this map: map.connect ":controller/:action/:id" This is the default map. So if none of the previous templates on the pattern fit, Rails tries to fit this last one. This pattern means that if I have an URI like /ticket/show/3, it means that it will instaniate the Ticket controller, execute the show action and put :id => 3 on the params hash, so it can be accessed through the action. So, as you see, this file is on the very heart of rails, and if properly used, it can help you simplify greatly your application URLS. Also is the most important file on RESTful applications, but thats another big topic. Regards, Jorge Corona. On Sep 5, 8:44 am, Palani Kumar <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > Can anyone please explain me why we need routes.rb also explain the > basic idea abt routes.rb file. > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---