rochester on rails: introduction to rails
Post on 06-May-2015
1.343 Views
Preview:
DESCRIPTION
TRANSCRIPT
Jason Morrison
January 19, 2006
Rochester on Rails
Ruby on RailsSustainable Productivity for Web Application Development
History
July 2004
DavidHeineimeier
Hansson
Extractedfrom
Basecamp
37signals
Hundreds of contributors
Thousands of revisions, tickets, and patches
Rails 1.0
December 13, 2005
What is Rails?
Full Stack
Web ApplicationFramework
It’s all Ruby!
(okay, except one file)
(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
Everything else is Ruby!
ActiveRecord
ActionPack
ERb views
ActionWebService
ActionMailer
Unit Testing
AJAX Helpers
Key Concepts
DRY:Don’t Repeat Yourself
+
Convention over configuration
=
Less code!
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>
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 }
order.rb
01 class Order < ActiveRecord::Base02 has_many :items03 end
Rails is expressive
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
#We’re slashing prices, all books are now half off!Product.find( :all, :conditions => “kind=‘book’” ) do |product| product.price *= 0.5 product.saveend
Increases Programmer
Railsincreases programmer…
Increases Programmer
Railsincreases programmerhappiness!
How does it fit together?
ModelView
Controller
ModelView
Controller
ActiveRecord
ActionPack}}
Ready, set, code!
top related