MVC Controllers
TestsMigrations Ye Olde Internet Model DB Server Router View Browser Today’s focus Controller
5 Basic Controller Patterns Create – new/create: Enter a new record Read – index: List all records – show: Display a particular record Update – edit/update: Modify an existing record Delete – destroy: Remove a record
5 Basic Controller Patterns Create – new/create: Enter a new record Read – index: List all records – show: Display a particular record Update – edit/update: Modify an existing record Delete – destroy: Remove a record
index Page
Ye Olde Internet Model DB Server Router View Browser How to implement index? Controller
Ye Olde Internet Model DB Server Router View Browser How to implement index? Controller 1.Route “index” URL pattern 2.Controller uses Model to retrieve records 3.Controller uses View to generate HTML (passes records to View) Demo Time!
5 Basic Controller Patterns Create – new/create: Enter a new record Read – index: List all records – show: Display a particular record Update – edit/update: Modify an existing record Delete – destroy: Remove a record ✔
new Form
Ye Olde Internet Model DB Server Router View Browser How many HTTP requests does it take to create a record? Controller
Ye Olde Internet Model DB Server Router View Browser How many HTTP requests does it take to create a record? Controller Two: One to request a form (GET) One to perform the add (POST)
Ye Olde Internet Model DB Server Router View Browser How to implement get form? Controller
Ye Olde Internet Model DB Server Router View Browser How to implement get form? Controller 1.Route URL pattern 2.Controller uses View to generate HTML (passes View records) 1 2
Ye Olde Internet Model DB Server Router View Browser How to implement post new record? Controller
Ye Olde Internet Model DB Server Router View Browser How to implement post new record? Controller 1.Route URL pattern 2.Controller uses Model to add rec 3.Controller sends HTTP redirect Demo Time!
5 Basic Controller Patterns Create – new/create: Enter a new record Read – index: List all records – show: Display a particular record Update – edit/update: Modify an existing record Delete – destroy: Remove a record ✔ ✔ Demo Time! Like index Like create Needs explaining…
Appendix
TestsMigrations Ye Olde Internet Model DB Server Router View Browser Controller