Basic Rails Projects Professor Larry Heimann Application Design & - - PowerPoint PPT Presentation

basic rails projects
SMART_READER_LITE
LIVE PREVIEW

Basic Rails Projects Professor Larry Heimann Application Design & - - PowerPoint PPT Presentation

Basic Rails Projects Professor Larry Heimann Application Design & Development Information Systems Program Why Ruby on Rails? Ruby on Rails is astounding. Using it is like watching a kung-fu movie, where a dozen bad-ass frameworks


slide-1
SLIDE 1

Basic Rails Projects

Professor Larry Heimann Application Design & Development Information Systems Program

slide-2
SLIDE 2

Why Ruby on Rails?

“Ruby on Rails is astounding. Using it is like watching a kung-fu movie, where a dozen bad-ass frameworks prepare to beat up on the little newcomer only to be handed their asses in a variety of imaginative ways.”

— Nathan Torkington

O'Reilly Program Chair for OSCON

slide-3
SLIDE 3

Automated tasks

  • rails new
  • rails generate
  • rails server
  • rails db:create
  • rails db:migrate
  • rails test:models
slide-4
SLIDE 4

Model basics

  • ActiveRecord does the heavy lifting
  • Basic relationships and validations
  • Other methods can be added

Key Idea: Models hold all the data & business logic

slide-5
SLIDE 5

History of Active Record

  • Did not originate with Rails!
  • Design pattern from Martin Fowler’s book Patterns of Enterprise

Application Architecture (2002)

  • “An object that wraps a row in a database table or view, encapsulates the

database access, and adds domain logic on that data.”

slide-6
SLIDE 6

Goals of Active Record

  • Make working with databases easier
  • Reduce repetition in code
  • Cut down on configuration needed to make applications work
slide-7
SLIDE 7

Migrations

slide-8
SLIDE 8

Migration Data Types

postgresql sqlite sqlserver bytea blob image boolean boolean bit date date datetime timestamp datetime datetime decimal decimal decimal float float float(8) integer integer int (note 1) varchar(255) varchar(255) text text text time datetime datetime timestamp datetime datetime db2 :binary blob(32768) :boolean decimal(1) :date date :datetime timestamp :decimal decimal :float float :integer int :string varchar(255) :text clob(32768) :time time :timestamp timestamp mysql

  • penbase
  • racle

blob

  • bject

blob tinyint(1) boolean number(1) date date date datetime datetime date decimal decimal decimal float float number int(11) integer number(38) varchar(255) char(4096) varchar2(255) text text clob time time date datetime timestamp date

slide-9
SLIDE 9

Class versus table names

slide-10
SLIDE 10

Plurals vs. Singular in Rails

OwnersController

  • wners table

has_many :pets @owner.pets Pet model belongs_to :owner @pet.owner

slide-11
SLIDE 11

Relationships (see examples in PATS)

slide-12
SLIDE 12

ActiveRecord creates SQL (examples given in class)

slide-13
SLIDE 13

Controllers in charge

  • Basic actions include: index, show, new, create, edit, update, delete
  • Controllers get needed data from models first
  • Actions connected automatically to view pages

Key Idea: Controller handle the process logic

slide-14
SLIDE 14

All about views

  • CSS and images
  • Layouts
  • Partials

Key Idea: Views only know what controllers tell them

slide-15
SLIDE 15

Comic of the Day...

slide-16
SLIDE 16

pItlh