Rails Layouts And Templates Lab
Objectives
Your task is to build an online store! Okay, maybe not a whole online store, but at least some layouts and controllers for an online store. Not only will you learn how to create a layout and how to get an action to use that layout but also how to override defaults and specify layouts on the action level.
The Default Layout
Make a new controller called
StaticController.Create a home view with an
h2that says "Welcome to Flatiron Widgets" and a new action inStaticControllercalledhome.Create a default application layout at the correct location, and add an
h1to it that says "Flatiron Widgets Store". This is for the main site's welcome bar.
Custom Layouts for a Controller
Create a new controller called
StoreAdminController.We want this controller to use a new layout called
admin. This layout should have anh1that says "Flatiron Widgets: Admin".Create a home view layout for
StoreAdminControllerwith anh2that says "Welcome Flatiron Admin".Get your newly created action to use the
admintemplate.
Custom Layouts for an Action
Create a new view for
StoreAdminControllercalledorderswith anh2that says "Welcome to Flatiron Open Orders". Also add anolwith a fewlielements containing fake orders.Now you should create a new layout called
order_administrationand add anh1that says "Flatiron Widgets: Open Orders".At this point, the
store_admin#ordersaction will use theadminlayout you defined earlier, but we need it to use the neworder_administrationlayout. The trick is we want only thestore_admin#ordersaction to use theorder_administrationlayout, and we want to keep theadminlayout as the default for the other actions inStoreAdminController.
Ignore Layouts for an Action
Create a new action in
StoreAdminControllercalledinvoice, and insert anh1that says "Your Invoice".This action is assigned the default layout for the controller,
admin, but we don't want it to use any layout at all (while also not affecting the layouts assigned to other actions in the controller).
Clone: https://github.com/learn-co-curriculum/rails-layouts-and-templates-lab
Last updated