2. Ruby on Rails history Ruby on Rails was extracted from 37signals’ Basecamp by David Heinemeier Hansson (DHH) July 2004: first released as open source Feb 2005: first external commit rights Oct 2007: ships with Mac OS X v10.5 "Leopard”
3. Rails Philosophy Opinionated Convention over configuration DRY (Don't Repeat Yourself) less code means it's easier to maintain & modify Test Driven Development (TDD) Minimal code - maximal effect
8. Ruby Gems A gem is a ruby library. gem –v 1.3.5 or higher gem list[sudo] gem install
9. Rails Rails is distributed as a Ruby gem. gem list rails 2.3.4 or higher [sudo] gem install rails
10. rake Rake is “make” for Ruby. Rails requires rake. Rake is distrubted as a gem. gem list rake0.8.7 or higher [sudo] gem install rake
11. Tools Source Code Control with Git Terminal / git bash on windows Editor / IDE Test Frameworks Herok for Easy Deployment
12. git Git is for source code control. which git (mac, unix) git bash on windows Why Git? Most Ruby and Rails developers use git Eco-system of tools Modern Source Code Control
21. MVC Model: ActiveRecord Represents what is in the database View: ActionView, erb Model rendered as HTML Controller: ActionController Receives HTTP actions (GET, POST, PUT, DELETE) Decides what to do, typically rendering a view
24. View Exercise 1. On the main people page a. Change “Listing people” to “My Class List” b. Remove the “Present” column 2. When you click “show,” the page should read “Joy McDonald was not present at class” or “Bob Smith was present at class”
25. ActiveRecord p = new Person p = new Person(:first => "May", :last => "Fong") p.save p.save! Person.create(:first => "May", :last => "Fong") Person.create!(:first => "May", :last => "Fong")
26. Safe from SQL injection class User < ActiveRecord::Base def self.authenticate_unsafely(user_name, password) find(:first, :conditions => "user_name = '#{user_name}' AND password = '#{password}'") end def self.authenticate_safely(user_name, password) find(:first, :conditions => [ "user_name = ? AND password = ?", user_name, password ]) end def self.authenticate_safely_simply(user_name, password) find(:first, :conditions => { :user_name => user_name, :password => password }) end end