ruby-on-railsrackactionpack

What is the difference between ActionPack and Rack? (Rails)


I'm trying to gain a deeper understanding of the Ruby on Rails framework and I've been doing a lot of googling about terms I've heard thrown around but never understood.

Two of these terms were "ActionPack" and "Rack"

According to the docs for each of these:

ActionPack:

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.

Rack:

Rack provides a minimal interface between webservers that support Ruby and Ruby frameworks.

From the googling I've been doing, I've put the following model together in my head, but I'm still a bit unsure:

If I understand correctly, Rack is more of a specification/standard for what an application/program should accept as input/produce as output (a program that does this being considered "rack compatible"). ActionPack is a the program rails uses to do this. So the request would go: Client HTTP request --> Server --> ActionPack --> The Rest of Rails etc.

Is this correct? Or have I misunderstood?


Solution

  • Many other frameworks can be Rack-based applications, such as Sinatra or Grape.

    To use Rack, provide an "app": an object that responds to the call method, taking the environment hash as a parameter, and returning an Array with three elements:

    The HTTP response code

    A Hash of headers

    The response body, which must respond to each

    That means: with rack you can interact with web requests directly, permitting the community to build different tools or frameworks that are based on that simple rule of interaction. The app object in question IS the framework.

    ActionPack is Rails' part that is interacting with Rack, it consists of a combination of ActionController and ActionView which makes our marvelous MVC architecture be as it is. Check this answer for a detailed view on ActionPack