Looking at the Readme of the Journey Router (which is the Rails 4.0 router), it is rather empty. I was wondering how the router works conceptually, and if this 'abstract' grammer is catching the idea, of the router as mini-programming-language:
ROUTE := GET|POST|PUT|DELETE path
path := (static_path) | (dynamic_path)
So, how does the Rails 4.0 Router work?
The Rails router recognizes URLs and dispatches them to a controller's action, or to a Rack application. It can also generate paths and URLs, avoiding the need to hardcode strings in your views. When your Rails application receives an incoming request for:
The Rails Router verifies if there is an entry matching the requested URL. We just need to configure the routes for this line: This will create RESTful routes for articles. If we run bundle exec rake routes, it will show the list of paths created. The HTTP verb can be GET, POST, PATCH, PUT, or DELETE.
In Rails, a resourceful route provides a mapping between HTTP verbs and URLs to controller actions. By convention, each action also maps to a specific CRUD operation in a database. A single entry in the routing file, such as: creates seven different routes in your application, all mapping to the Photos controller:
Routes should be included in your testing strategy (just like the rest of your application). Rails offers three built-in assertions designed to make testing routes simpler: assert_generates asserts that a particular set of options generate a particular path and can be used with default routes or custom routes. For example:
If you want to understand Rails routing, the best place to start is Rails Routing from the Outside In in the edge guide.
After that, you'll have more luck looking at ActionDispatch::Routing
's docs.
Note: The following relates to Journey v1.0.4, which was the latest at time of writing.
Journey itself is the Rails routing engine introduced in Rails 3.2. In the release notes, it is described with a single statement: "Route recognition also got a bunch faster thanks to the new Journey engine." That's not a lot of info specifically about Journey, of course, but Rails doesn't describe every implementation detail; that would take forever! :) Journey's gemspec also describes itself with the statement: "Journey is a router. It routes requests."
You could look at the api docs, but in v1.0.4, it has extremely sparse documentation (Journey::Router::Utils.normalize_path(path) is documented) other than the code itself and maybe its open and closed issues. You could take a look at the other S.O. posts with tag journey.
Some of the code is somewhat self-descriptive just via method names, etc. like in Journey::Routes. Journey's tests are also a great way to see how it works.
Some notes on the code itself:
rails c
then Journey::Path::Pattern.new(9)
)Journey's visualizer might be interesting to play around with, also (note visualizer method in Journey::GTG::TransitionTable). Sample visualization here, and online demo here for now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With