UPenn on Rails
  Lesson 1: Data and Views
Data

Views
Data
class Team


• name
• (id, created_at, updated_at)
class Location

• name
• address
• (id, created_at, updated_at)
class Game
• starts_at
• ends_at
• location
• home_team
• away_team
• (id, created_at, updated_at)
class Game
• starts_at
• ends_at                  class Location
• location
• home_team
• away_team
• (id, created_at, updated_at)
class Game
• starts_at
• ends_at                  class Location
• location
• home_team                       class Team
• away_team
• (id, created_at, updated_at)
CODE!
Database Migrations

• live in db/migrate
• ordered
• Abstracted SQL column types
• includes id and timestamps by default
MORE CODE!
RESTful Routes

• GET /locations (show all locations)
• GET /locations/3 (show one location)
• POST /locations (make a location)
• PUT /locations/3 (update one location)
Can also be nested


• GET /locations/3/games (show games for
  one location)
‘public’ folder

• For all static files
• Rails looks here first
• Offers caching options
Views
ERB

• Like JSP/ASP, but in ruby
• lots of helper functions for forms, etc.
• layout → view → partials
VIEW CODE!
ActiveRecord
        Associations

• 1 to 1 (belongs_to - has_one)
• 1 to many (belongs_to - has_many)
• many to many (has_many :through)
Other points


• Controllers
• Next class: User stories and testing!
Homework
• Make a Player scaffold
• Show the players for a given team on that
  team’s page
• (bonus) assign players on the team edit
  page
• Help at http://railsforzombies.org/

UPenn on Rails pt 1