Your SlideShare is downloading. ×
Ruby On Rails Intro
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Ruby On Rails Intro

2,350
views

Published on

Intro to Ruby and Rails, including development environment, MVC, erb and ActiveRecord

Intro to Ruby and Rails, including development environment, MVC, erb and ActiveRecord

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,350
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
26
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Ruby on RailsAn Introduction
    Sarah Allen
    Blazing Cloud
  • 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
  • 4. What you will learn
    Ruby
    Language concepts
    Language syntax
    Common patterns
    Rails Framework: creating web applications
    Scaffold
    Model, View, Controllers, Routes
    SQL Queries, log files and debugging
    Associations
  • 5. How you will learn
    Exploration: experiment, play
    Test-Driven Development (TDD)
    Initially as a learning methodology
    Later as a development methodology
    Ask questions
    Learn to find your own answers
  • 6. Class Structure
    Talk
    Live Coding Demonstrations
    In-class coding
  • 7. Prerequistes
    Core dependencies: Ruby, Rails, DB
    Tools: vcs, IDE, test frameworks, deployment
  • 8. Core Dependencies
    Ruby
    Rails
    Rake
    Database
  • 9. Ruby
    Rails is a framework
    written in the Ruby language.
    Great Rails developers
    are great Ruby developers.
  • 10. The Ruby Language
    Originally by Yukihiro "Matz" Matsumoto
    “Ruby is designed for programmer productivity and fun, following the principles of good user interface design. He stresses that systems design needs to emphasize human, rather than computer, needs.”
    http://en.wikipedia.org/wiki/Ruby_(programming_language)#History
    Ruby 1.0 was released in 1996.
  • 11. Ruby
    ruby -v
    1.8.6 or 1.8.7
  • 12. Ruby Versions
    ruby -v
    1.8.6 – most common
    1.8.7 – some 1.9 features, very compatible
    1.9.1 – latest version, many VMs, Rails 2.3
    YARV (yet another Ruby VM) faster than MRI
    JRuby (Java)
    Rubinius (pure ruby)
    IronRuby (.NET)
    MacRuby, HotCocoa
    HotRuby/RubyJS (Flash/Javascript)
  • 13. Ruby Gems
    A gem is a ruby library.
    gem –v 1.3.5 or higher
    gem list[sudo] gem install
  • 14. Rails
    Rails is distributed as a Ruby gem.
    gem list rails 2.3.4 or higher
    [sudo] gem install rails
  • 15. 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
  • 16. Database
    SQLite for class with sqlite3-ruby gem
    Other databases:
    MySQL
    PostgreSQL
    Oracle
    SQL Server
    SyBase
    DB2
  • 17. Tools
    Source Code Control with Git
    Terminal / git bash on windows
    Editor / IDE
    Test Frameworks
    Heroku for Easy Deployment
  • 18. 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
  • 19.
  • 20. command line
    Mac/Unix Terminal
    GitBash on Windows
  • 21. Editor / IDE
    RubyMine
    TextMate (Mac-only)
    Komodo (free)
  • 22. Test Frameworks
    gem list rspec
    rspec (1.3.0)
    rspec-rails (1.3.2)
    gem list cucumber
    cucumber (0.6.2)
    cucumber-rails (0.2.4)
  • 23. Heroku
    Simple cloud hosting
    Web sign-up for free account: heroku.com
    [sudo] gem install heroku
  • 24. Prerequisites
    Core dependencies
    Ruby
    Ruby Gems
    Rails (gem)
    Rake
    Database
    Tools
    Git
    Terminal / git bash on windows
    Test Frameworks
    rspec, rspec-rails
    cucumber, cucumber-rails
    Heroku (for deployment)
  • 25. Let’s Get Started
  • 26. Lets get started
    IRB: InteractiveRuBy
    >> 4
    >> 4 + 4
  • 27. Everything is an object
    “test”.upcase
    “test”.class
    “test”.methods
  • 28. Everything evaluates to something
    2 + 2
    (2+2).zero?
  • 29. Methods are Messages
    thing.do(4)
    thing.do 4
    thing.send “do”, 4
  • 30. Operators are Methods
    thing.do 4
    thing.do(4)
    thing.send “do”, 4
    1 + 2
    1.+(2)
    1.send "+", 2
  • 31. Defining Classes
    Let’s write some code!
  • 32. Test-First Learning
    Similar methodology to TDDwith a different purpose and workflow
    Teacher writes the test
    Student implements the code
  • 33. Test-Driven Development
    Design
    Focus / Project Management
    Creation of Tests
  • 34. Introduction to Rspec
    Describe the feature
    Verify expectation
  • 35.
  • 36. Scaffold
    Model
    app/models/person.rb
    db/migrate/20090611073227_create_people.rb
    4 views
    app/views/people/index.html.erb
    app/views/people/show.html.erb
    app/views/people/new.html.erb
    app/views/people/edit.html.erb
    Controller
    app/controllers/people_controller.rb
    route map.resources :people
  • 37. 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
  • 38. MVC
  • 39. views
    <% @people.each do |person| %>
    <tr>
    <td><%=h person.first_name %></td>
    <td><%=h person.last_name %></td>
    <td><%=h person.present %></td>
    </tr>
    <% end %>
  • 40. 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”  
  • 41. 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")
  • 42. 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