Rails Request Cycle

I’d like you to write a blog article defining how a URL goes from being a URL to returning customized HTML.

For example, use the following three URLs:

  1. /
  2. /gifs
  3. /gifs/23463-cats-jumping

I’d like you to cover the router, the controller, action, params, and templates, describing who passes to what, in what order, and how it all works together on a conceptual level. Cover the difference between a “layout” and a “template”

……..

Surfing web for cat gifs. A request for a URL is sent from my browser to a server. Server then asks Rails for some direction on where to go next. This helpful information is stored in the application’s router.rb file. The router file serves as a map that recognizes URL requests and sends them to the appropriate controller#action. Once the router has identified the correct controller for a specific URL request, the controller “takes action” by manipulating data inside of a controller.rb file. This data is then passed into the controller’s accompanying action. Depending on the URL, this data could be passed off with a parameter identifying a specific instance (/gifs/23463-cats-jumping ). These actions (list, view) are .erb html templates that give the data order for rendering on a webpage. Once html has been generated by our .erb, Rails passes this info package back to the server which then passes it along to my browser and a page loads with cat pictures.

P.S. a layout is kind of like a template’s template. My other understanding at this point is that the layout is somewhat of a common framework for all templates. Layouts include erb <%= yield %> which is replaced by view(template put into action by controller according to URL), so we end up with a template nested inside of a layout.