tkymtk's blog

Ruby on Rails及びその周辺について調べたこと。Do whatever you want to do at your own pace.

アクションパック- リクエストからレスポンスまで

Action Pack – From request to response

Action Pack はwebリクエストに対して処理とレスポンスを返すためのフレームワーク。 Action Packが提供するものは:

  • ルーティング(routing)する(リクエストURLをアクションに割り付ける)仕組み。
  • アクションを実装するコントローラー(controllers)を定義する。
  • ビュー(views)レンダリングすることでレスポンスを生成する。

一言で言えば、Action PackはMVCダイアグラムのビューとコントローラーを提供する。

Action Packはいくつかのモジュールから成り立っていて:

  • Action Dispatch - Action Dispatchはwebリクエストに関する情報を解析して、ユーザによって定義された通りルーティングの処理をする。 そして

    • MIME-type negotiation
    • POSTやPATCH、PUT本体内のパラメータのデコード
    • HTTP キャッシングロジック、クッキー、セッションの処理

といったようなHTTPに関連したより高度な処理をする。

  • Action Contoller - Action Controllerは基礎となるコントローラークラスを提供する。 このクラスはフィルターやリクエストの処理をするといったアクションを実装するために、 継承してサブクラスをつくることもできる。一つのアクションの結果は、大概はビューから生成されたコンテンツである。

Ruby on Railsフレームワークでは、ユーザはAction Controllerモジュールと直接やりとりするだけである。 必要なAction Dispatch機能はデフォルトで機能しており、Action ViewレンダリングはAction Controllerによって暗黙の うちに起動される。しかし、これらのモジュールは単体で機能するように設計されており、Railsの外で使うこともできる。

Action Pack – From request to response

Action Pack is a framework for handling and responding to web requests. It provides mechanisms for routing (mapping request URLs to actions), defining controllers that implement actions, and generating responses by rendering views, which are templates of various formats. In short, Action Pack provides the view and controller layers in the MVC paradigm.

It consists of several modules:

  • Action Dispatch, which 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.

  • Action Controller, which provides a base controller class that can be subclassed to implement filters and actions to handle requests. The result of an action is typically content generated from views.

With the Ruby on Rails framework, users only directly interface with the Action Controller module. Necessary Action Dispatch functionality is activated by default and Action View rendering is implicitly triggered by Action Controller. However, these modules are designed to function on their own and can be used outside of Rails.

簡易訳ですので、間違いがあればご指摘願います。

ところで、

RailsGuidesを見ると

Action View and Action Controller are the two major components of Action Pack.

GitHubを見ると

It (Action Pack) consists of several modules: Action Dispatch, Action Controller.

と書かれている。
上の情報をまとめると、 Action Packの主なコンポーネント

  • Action Dispatch
  • Action View
  • Action Controller

ということになる。
gitHubを見る限り確かにAction ViewのフォルダはAction Packと独立しているが、 内部から呼んでいるのだろうか。

間違いがあれば、ご指摘下さると幸いです。