In the last chapter, we worked on implementing a solid model layer for the application. While the console and unit tests are a fine way for developers to access the models, they are not a suitable interface for the intended users of the system (Acme administrative staff). This chapter describes how to build a web interface onto the models we have developed, including:
By the end of the chapter, we will have a basic, fully-functional web-based CRM application.
The model layer of the last chapter is the first part of the Model-View-Controller jigsaw. Implementing a user interface on top of the model layer means building the two remaining MVC components (see the section Model-View-Controller Architecture at the start of Chapter 4):
How do you decide which controllers and views do you need to build? Rails helps us with our decision making by suggesting a convention: one controller for each model. The controller for the model handles all of the operations on it; typically the CRUD operations, i.e.
Making a controller for each model seems a sensible place to start. In the rest of the chapter, we will build up the following controllers, corresponding to the models we built in the previous chapter:
Controller class |
File containing controller definition (in |
---|---|
PeopleController |
|
CompaniesController |
|
AddressesController |
|
Notice how we are applying the conventions mentioned in Chapter 4 (Rails and MVC): the controller name is the name of the model, pluralized, with "Controller" appended. The file name is the lowercase version of the controller class name, with underscores separating discrete words.
We'll be looking at the workflow for building a simple controller, explaining where to put the code that defines the controller actions and where to put the associated views. Along the way, we'll see how to organize the layout for your application and customize the look and feel with a stylesheet.
3.147.59.219