This is the first of 8 presentations given at University of Texas during my Beginner to Builder Rails 3 Class. For more info and the whole series including video presentations at my blog:
http://schneems.tumblr.com/tagged/Rails-3-beginner-to-builder-2011
5. Rails - Week 1
•Workspace
• Version Control - Keep your code safe
• RubyGems - Use other’s code
• Bundler - Manage Dependencies
• RVM - Keep your system clean
• Tests - make sure it works
@Schneems
Friday, June 10, 2011
6. Ruby Versus Rails
• Ruby - Is a programming Language
• Like C# or Python
• Can be used to program just about anything
• Rails - Is a Framework
• Provides common web functionality
• Focus on your app, not on low level details
@Schneems
Friday, June 10, 2011
7. Rails is a Web Framework
• Develop, deploy, and maintain dynamic web apps
• Written using Ruby
• Extremely flexible, expressive, and quick
development time
@Schneems
Friday, June 10, 2011
8. Technologies
• Html - creates a view
• Javascript - makes it interactive
• css - makes it pretty
• Ruby - Makes it a web app
@Schneems
Friday, June 10, 2011
15. Ruby Symbols
•Symbols are lightweight strings
• start with a colon
• immutable
:a, :b or :why_the_lucky_stiff
:why_the_lucky_stiff.class
>> Symbol
@Schneems
Friday, June 10, 2011
16. Ruby Hash
•A hash is a dictionary surrounded by curly
braces.
•Dictionaries match words with their definitions.
my_var = {:sup => "dog", :foo => "bar"}
my_var[:foo]
>> "bar"
{:sup => "dog", :foo => "bar"}.class
>> Hash
@Schneems
Friday, June 10, 2011
17. Ruby Array
•An array is a list surrounded by square
brackets and separated by commas.
array = [ 1, 2, 3, 4 ]
array.first
>> 1
[ 1, 2, 3, 4 ].class
>> Array
@Schneems
Friday, June 10, 2011
19. Ruby Blocks
•Code surrounded by curly braces
2.times { puts "hello"}
>> "hello"
>> "hello"
•Do and end can be used instead
2.times do
puts "hello"
end
>> "hello"
>> "hello"
@Schneems
Friday, June 10, 2011
20. Ruby Blocks
•Can take arguments
• variables surrounded by pipe (|)
2.times do |i|
puts "hello #{i}"
end
>> "hello 0"
>> "hello 1"
@Schneems
Friday, June 10, 2011
21. Rails why or why-not?
• Speed
• developer vs computer
• Opinionated framework
• Quick moving ecosystem
@Schneems
Friday, June 10, 2011
24. Convention over
Configuration
Decrease the number of decisions needed,
gaining simplicity but without losing flexibility.
@Schneems
Friday, June 10, 2011
25. Model-View-Controller
• Isolates “Domain Logic”
• Can I See it?
• View
• Is it Business Logic?
• Controller
• Is it a Reusable Class Logic?
• Model
@Schneems
Friday, June 10, 2011
26. Model-View-Controller
• Generated By Rails
• Grouped by Folders
• Connected “AutoMagically”
• Models
• Views
• Controllers
• Multiple Views Per Controller
@Schneems
Friday, June 10, 2011
27. Database Backed Models
• Store and access massive amounts of
data
• Table
• columns (name, type, modifier)
• rows
Table: Users
@Schneems
Friday, June 10, 2011
28. SQL
• Structured Query Language
• A way to talk to databases
SELECT *
FROM Book
WHERE price > 100.00
ORDER BY title;
@Schneems
Friday, June 10, 2011
29. SQL operations
• insert
• query
• update and delete
• schema creation and modification
@Schneems
Friday, June 10, 2011
30. Object Relational Mapping
• Maps database backend to ruby objects
• ActiveRecord (Rail’s Default ORM)
>> userVariable = User.where(:name => "Bob")
Generates:
SELECT "users".* FROM "users"
WHERE (name = 'bob')
>> userVariable.name
=> Bob
@Schneems
Friday, June 10, 2011
31. Object Relational Mapping
• >> userVariable = User .where(:name => "Bob")
models/user.rb
class User < ActiveRecord::Base
end
the User class inherits from ActiveRecord::Base
@Schneems
Friday, June 10, 2011
32. Object Relational Mapping
• >> userVariable = User. where(:name => "Bob")
where is the method that looks in the database
AutoMagically in the User Table (if you made one)
@Schneems
Friday, June 10, 2011
33. RESTful
REpresentational State Transfer
• The state of the message matters
• Different state = different message
“You Again?” “You Again?”
@Schneems
Friday, June 10, 2011
34. RESTful
REpresentational State Transfer
• Servers don’t care about smiles
• They do care about how you access them
• (HTTP Methods)
• GET
• PUT
• POST
• DELETE
@Schneems
Friday, June 10, 2011
35. RESTful
REpresentational State Transfer
• Rails Maps Actions to HTTP Methods
• GET - index, show, new
• PUT - update
• POST - create
• DELETE - destroy
@Schneems
Friday, June 10, 2011
36. Work Environment
• Version Control - Keep your code safe
• RubyGems - Use other’s code
• Bundler - Manage Dependencies
• RVM - Keep your system clean
• Tests - make sure it works
@Schneems
Friday, June 10, 2011
37. Version Control
• my_last_update_1.rb
• my_realy_last_update_2.rb
• really_the_good_code_last_final_new.rb
@Schneems
Friday, June 10, 2011
38. Version Control
• my_last_update_1.rb
• my_realy_last_update_2.rb
• really_the_good_code_last_final_new.rb
@Schneems
Friday, June 10, 2011
39. Version Control
• my_last_update_1.rb
• my_realy_last_update_2.rb
• really_the_good_code_last_final_new.rb
@Schneems
Friday, June 10, 2011
40. Version Control
• Make note of whats different
• See changes over time
• revert back to known state
• work with a team
@Schneems
Friday, June 10, 2011
41. Version Control
• Git (recommended)
• SVN
• Mecurial
• Perforce
• Many More
@Schneems
Friday, June 10, 2011
42. Github
http://github.com
@Schneems
Friday, June 10, 2011
46. Bundler
• Install
bundle install
• installs all gems listed in gemfile
• very useful managing across systems
@Schneems
Friday, June 10, 2011
47. RVM
• Ruby Version Manager
• Clean Sandbox for each project
rvm use ruby-1.8.7-p302
rvm use ruby-1.9.2-p180
@Schneems
Friday, June 10, 2011
48. RVM
• Use fresh gemset for each project
rvm gemset use gowalla
• Switch projects...switch gemsets
rvm gemset use keytar
@Schneems
Friday, June 10, 2011
49. Testing
• Does your code 6 months ago work?
• What did it do again?
• Manual Versus Programatic
• Save Time in the long road by
progamatic Testing
@Schneems
Friday, June 10, 2011
50. Testing
• Test framework built into Rails
• Swap in other frame works
• Use Continuous Integration (CI)
• All tests green
• When your(neverapp breaks, write a
test for it
web
again)
@Schneems
Friday, June 10, 2011
51. IDE
• Mac: Textmate
• Windows: Notepad ++
• Eclipse & Aptana RadRails
@Schneems
Friday, June 10, 2011
52. Recap
• Rails
• Framework
• Convention over Configuration
• Ruby
• Expressive Scripting language
@Schneems
Friday, June 10, 2011