Changes to the user interface should be easy, and even possible at
Supporting different 'look and feel' standards or porting the user
interface should not affect code in the core of the application.
The separation of the model from view and controller components
allows multiple views of the same model.
- The model component encapsulates core data and functionality. The
model is independent of specific output representations or input
Provides functional core of the application.
Registers dependent views and controllers.
Notifies dependent components about data changes.
- View components display information to the user. A view obtains the
data from the model. There can be multiple views of the model.
- Each view has an associated controller component. (!?)
Each view creates a suitable controller. There is a one-to-one relationship between views and controllers. Views often offer functionality that allows controllers to manipulate the display.
- Creates and initializes its associated controller.
- Displays information to the user.
- Implements the update procedure.
- Retrieves data from the model.
- The user interacts with the system solely through controllers.
- Accepts user input as events.
- Translates events to service requests for the model or display requests for
- Implements the update procedure, if required.
With components, this is no longer the case. Instead of altering the WeblogController to gather the Image, you can now add a method to the ImageController to handle this. Let’s say you call it “recent_image”. At this point, you’d also define a view for recent_image that only returned an HTML snippet displaying that Image in some fashion. Then, in the Weblog view, you’d simply add something like: <%= render_component(:controller => 'image', :action => 'recent_image') %>. When this point in the view was reached, Rails would use the ImageController to gather the data from the Image model, populate that view, and return it, in place, within the view for your WeblogController.