-
Notifications
You must be signed in to change notification settings - Fork 125
Presenters and Views Development Pattern
E. Lynette Rayle edited this page Feb 17, 2022
·
3 revisions
NOTE: At this writing, all links are to code in Release 3.3.0.
A Presenter sits between a Controller and a View to incapsulate the data in the Controller. The Presenter defines methods and variables to provide a consistent API for the View to access the data it needs. The View should not need to access the Controller directly.
Term | Description |
---|---|
Controller | Part of the MVC (model-view-controller) that processes requested CRUD (create, read, update, delete) actions. It creates the Presenter and passes it the data it needs to support a View. |
Presenter | Created by the controller, it wraps the data provided by the controller to create a consistent and incapsulated API for views. The Controller creates the Presenter passing it the data it needs to be able to support a View. |
View | Part of the MVC that displays forms and information in the UI that facilitate CRUD. It SHOULD only access data through methods and variables provided by the Presenter. |
- Controllers are defined in /app/controllers
- Presenters are defined in /app/presenters
- Views are defined in /app/views
They follow naming conventions SHOULD be followed:
- each SHOULD have the same sub-directory structure (starting after the directories listed above) For example:
- /app/controllers/hyrax/dashboard
- /app/presenters/hyrax/dashboard
- /app/views/hyrax/dashboard
- each SHOULD have the same prefix filename (e.g. for collections, they will each start with collections) For example:
- collections_controller.rb
- collections_presenter.rb
- collections.erb.html OR collections/index.erb.html, new.erb.html, edit.erb.html, etc.
NOTE: Some code exists that does not follow this naming convention and it makes it difficult for developers to locate the related files. Although the conventions above say SHOULD, this could be written as MUST. The wording reflects the fact that lack of a file following the naming convention does not imply that it doesn't exist.