Domanda

I have a fairly decent grasp on the basic Rails concepts like ActiveRecord, routing, migrations, etc. One thing I'm having a hard time understanding is ActionDispatch. I can't find a plain-English description (or really any description) of what it is. So what is it?

È stato utile?

Soluzione

In one, short sentence: Action Dispatch routes requests to controllers. For the more detailed explanation, I would recommend reading "Action Dispatcher and Action Controller in Rails 4".


Action Dispatch & Action Controller

Altri suggerimenti

Action Dispatch is really just bunch of code which has following responsibilities. It parses information about the web request, handles routing as defined by the user, and does advanced processing related to HTTP such as MIME-type negotiation, decoding parameters in POST, PATCH, or PUT bodies, handling HTTP caching logic, cookies and sessions.

In my opinion, Alex Taylor gave the best explanation to what Dispatcher is:

Dispatcher is a small class which is responsible for instantiating the controller and passing along our request, along with an empty response object. It’s invoked when a suitable route is identified for a request. It has no knowledge about how a request arrived on its doorstep, but it knows what to do when it sees our request: instantiate the UsersController and hand it our request. As we’ll see, it acts as an object factory for our controllers, removing the need for us to declare our controller classes anywhere outside of the classes themselves.

Full article: A Deep Dive into Routing and Controller Dispatch in Rails

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top