small medium large xlarge

29 Apr 2013, 17:56
Enrique Sánchez (17 posts)

Why are we writing the CurrentCart module inside the “concerns” folder instead of “carts_controller.rb”?

And why did Rails generate all that code in “carts_controller.rb”? By generating the scaffold for a cart does it know we mean a “shopping cart”?

30 Apr 2013, 20:21
Sam Ruby (584 posts)

The concerns directory is where you place code that can be shared between controllers. By the time you complete part 2, the CurrentCart module will be included by the LineItemsController, OrderController, and StoreController.

Whenever you use the scaffold generator, it will fully populate 6 methods for you. Rails doesn’t “know” that this is a shopping cart, it merely understands that it is a resource that has many LineItems. The “shopping-cartness” is what you add by tailoring the generated files.

You must be logged in to comment