I was working on PHP in the past 1 year and nowadays I’m learning Rails.
In rails:–
Routing takes an incoming URL and decodes it into a set of parameters that are used by Rails to dispatch to the appropriate controller and action
For example
rs.recognize_path "/blog/show/123"
{:controller=>"blog", :action=>"show", :id=>"123"}
Am I right?
We mention this (written down) line of code in our routes.rb under config directory to tell rails how to handle the request like “/blog/show/123” using this line of code.
map.connect "blog/show/:id", :controller => "blog", :action => "show", :id => /\d+/
Now in PHP when we do something like this
www.example.com/profile.php?profile_id=2
How is the request sent to the requested page? Means I never wrote anything for routing in PHP, so how hss this request been handled?
How is the routing done in PHP (anything I missed during my learning/working in PHP)?
Hopefully you get what I am asking. Please let me know if there is any part unclear.
With your PHP example, the page is found by looking at the given path
profile.php. This file is searched for by your webserver and (if found) executed.In Rails the URLs are matched against routes to find the corresponding controller. In your Rails example
blogis mapped against theBlogController. Now Rails knows that the file containing the controller can be found asapps/controllers/blog_controller.rb.Each controller has actions so the
showpart is matched against theshowaction of the BlogController, which is represented by ashowmethod in the controller.For information about Rails routes, read the Routing Guide of Rails.
So to be short