Advanced Web Development Robert W. Hasker Milwaukee School of Engineering Goals

• Course overview • Introduction to the Rails framework • Introduction to Ruby Course Overview

• Review Syllabus ▫ Subgoal: engineering active websites • Reading: ▫ Textbook: Agile Web Development with Rails 4 ▫ Supplement: Programming Ruby: The Pragmatic Programmer's Guide  Read chapters 1-5 • Lab prep: do assignment 0 • First: what is Rails? The Rails Framework

• Basic goal: construct -backed websites • Multi-platform: popular OS’s, database engines • Origins: ▫ Instiki by David Heinemeier Hansson ▫ Basecamp by 37signals ▫ Rails: domain-independent core • Built on the Ruby language ▫ General-purpose language: scripting, applications ▫ Dynamically typed, “open” classes Basic Concept: MVC • Issue: how to separate logic from presentation? • Classic solution: Model/View/Controller ▫ Model: domain-level data ▫ View: how the data is presented to the user  Typically want multiple views ▫ Controller: logic linking the two • Rails ▫ Model = tables in a relational database ▫ View = web pages ▫ Controller = controller Basic Concepts: Active Record

• Relational : organize large amounts of data ▫ Issue: no easy mapping to object-oriented design • Active Record Pattern ▫ A design pattern first described by Martin Fowler ▫ Object = row w/ attributes stored as columns ▫ Table = collection of objects ▫ OOD = database (collection of tables)  Rails: link classes through id fields in tables Active Record Example • Data for a simple voting system:

• As tables: ▫ create table questions (id int, body text, start datetime, end datetime, (id)); ▫ create table voters (id int, username text, password text, primary key(id)); ▫ create table vote_records (voter_id int, …); • Benefit: can add operations as needed - active records Using rails to build a voting application

• See //faculty-web.msoe.edu/hasker/webdev/notes/rails-voting- demo.html Review • Rails: a tool for building quick, OO websites • Sound design ▫ MVC: organization ▫ ActiveRecord: combining OO & relational database • Minimal setup ▫ convention, not configuration ▫ many relationships are declared explicitly • Development support ▫ Prototyping with scaffolding ▫ Tools: helpers ▫ has full debugging support; separate dev/prod dbs • Next: programming in Ruby