Download - Rochester on Rails: Introduction to Rails

Transcript
Page 1: Rochester on Rails: Introduction to Rails

Jason Morrison

January 19, 2006

Rochester on Rails

Ruby on RailsSustainable Productivity for Web Application Development

Page 2: Rochester on Rails: Introduction to Rails

History

Page 3: Rochester on Rails: Introduction to Rails

July 2004

DavidHeineimeier

Hansson

Page 4: Rochester on Rails: Introduction to Rails

Extractedfrom

Basecamp

Page 5: Rochester on Rails: Introduction to Rails
Page 6: Rochester on Rails: Introduction to Rails

37signals

Page 7: Rochester on Rails: Introduction to Rails
Page 8: Rochester on Rails: Introduction to Rails

Hundreds of contributors

Thousands of revisions, tickets, and patches

Page 9: Rochester on Rails: Introduction to Rails

Rails 1.0

December 13, 2005

Page 10: Rochester on Rails: Introduction to Rails
Page 11: Rochester on Rails: Introduction to Rails

What is Rails?

Page 12: Rochester on Rails: Introduction to Rails

Full Stack

Page 13: Rochester on Rails: Introduction to Rails

Web ApplicationFramework

Page 14: Rochester on Rails: Introduction to Rails

It’s all Ruby!

Page 15: Rochester on Rails: Introduction to Rails

(okay, except one file)

Page 16: Rochester on Rails: Introduction to Rails

(here it is)database.yml

development: adapter: sqlite dbfile: db/dev.db

test: adapter: sqlite dbfile: db/test.db

production: adapter: sqlite dbfile: db/prod.db

Page 17: Rochester on Rails: Introduction to Rails

Everything else is Ruby!

Page 18: Rochester on Rails: Introduction to Rails

ActiveRecord

Page 19: Rochester on Rails: Introduction to Rails

ActionPack

Page 20: Rochester on Rails: Introduction to Rails

ERb views

Page 21: Rochester on Rails: Introduction to Rails

ActionWebService

Page 22: Rochester on Rails: Introduction to Rails

ActionMailer

Page 23: Rochester on Rails: Introduction to Rails

Unit Testing

Page 24: Rochester on Rails: Introduction to Rails

AJAX Helpers

Page 25: Rochester on Rails: Introduction to Rails

Key Concepts

Page 26: Rochester on Rails: Introduction to Rails

DRY:Don’t Repeat Yourself

Page 27: Rochester on Rails: Introduction to Rails

+

Page 28: Rochester on Rails: Introduction to Rails

Convention over configuration

Page 29: Rochester on Rails: Introduction to Rails

=

Page 30: Rochester on Rails: Introduction to Rails

Less code!

Page 31: Rochester on Rails: Introduction to Rails

Order.hbm.xml

01 <hibernate-mapping>02 <class name="models.Order" table="ORDERS"03 dynamic-update="true" dynamic-insert="false">06 <id name="id" column="id" type="java.lang.Long" 07 unsaved-value="null">08 <generator class="identity"/>09 </id>10 <set name="items" lazy="false" inverse="false"11 cascade="none" sort="unsorted">12 <key column="id"/>13 <one-to-many class="models.Item"/>14 </set>15 <property name="name" type="java.lang.String"16 update="true" insert="true"17 access="property" column="name"/>18 </class>19 </hibernate-mapping>

Page 32: Rochester on Rails: Introduction to Rails

Order.java

01 public class Order {02 private Set items;03 private String name;04 private Long id;05 06 public Long getId() { return id;}07 public void setId(Long id) { this.id = id;}08 public Set getItems() { return items;}09 public void setItems(Set items) { this.items = items; }10 public String getName() { return name; }11 public void setName(String name) { this.name = name; }12 }

Page 33: Rochester on Rails: Introduction to Rails

order.rb

01 class Order < ActiveRecord::Base02 has_many :items03 end

Page 34: Rochester on Rails: Introduction to Rails

Rails is expressive

Page 35: Rochester on Rails: Introduction to Rails

class Project < ActiveRecord::Base belongs_to :portfolio has_one :project_manager has_many :milestones has_and_belongs_to_many :categories validates_presence_of :name, :description validates_acceptance_of :non_disclosure_agreement validates_uniqueness_of :keyend

Page 36: Rochester on Rails: Introduction to Rails

#We’re slashing prices, all books are now half off!Product.find( :all, :conditions => “kind=‘book’” ) do |product| product.price *= 0.5 product.saveend

Page 37: Rochester on Rails: Introduction to Rails

Increases Programmer

Railsincreases programmer…

Page 38: Rochester on Rails: Introduction to Rails

Increases Programmer

Railsincreases programmerhappiness!

Page 39: Rochester on Rails: Introduction to Rails

How does it fit together?

Page 40: Rochester on Rails: Introduction to Rails

ModelView

Controller

Page 41: Rochester on Rails: Introduction to Rails

ModelView

Controller

ActiveRecord

ActionPack}}

Page 42: Rochester on Rails: Introduction to Rails
Page 43: Rochester on Rails: Introduction to Rails

Ready, set, code!