• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
PTW Rails Bootcamp
 

PTW Rails Bootcamp

on

  • 717 views

 

Statistics

Views

Total Views
717
Views on SlideShare
717
Embed Views
0

Actions

Likes
0
Downloads
6
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • What are you interested/concerned about?\n- jobs\n- community involvement\n- notoriety\n- easy\n- fun\n
  • - Cake PHP, Symphony?\n- Spring Roo, MVC?\n- Django?\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Or no database. Use sqlite to get even your designers up and running quickly.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

PTW Rails Bootcamp PTW Rails Bootcamp Presentation Transcript

  • Rails BootcampPhilly.rb PhillyTechWeek
  • Mat Schaffer mat@mashion.net @matschaffer matschaffer.com
  • • Chapter 1: Overview and Installation• Chapter 2: Data and Views• Chapter 3: User Stories and Testing• Chapter 4: Hack time
  • Chapter 1: Overview• Why Rails?• Rails overview• Dealing with Data• Live Console and Testing
  • Why Rails?
  • Rails Overview
  • • Developed for BaseCamp by 37 signals• DSL for web applications
  • Controller
  • Controller
  • ControllerModel
  • ControllerModel
  • ControllerModel View
  • ControllerModel View
  • Convention over Configuration
  • GET /commentsCommentsController#index views/comments/index.html.erb
  • GET /comments/4CommentsController#showviews/comments/show.html.erb
  • GET /comments/4.jsCommentsController#showviews/comments/show.js.erb
  • Data
  • More Convention over Configuration
  • Super simple•C reate•R etreive•U pdate•D elete
  • Comment.create(:author => "mat")INSERT INTO comments(author) VALUES(mat);
  • Comment.find_by_author("mat")SELECT * FROM commentsWHERE author = mat;
  • c = Comment.find(1)c.update_attribute(:author, "mat")SELECT * FROM comments WHERE id = 1;UPDATE comments SET author = mat WHEREid = 1;
  • c = Comment.find(1)c.destroySELECT * FROM comments WHERE id = 1;DELETE FROM comments WHERE id = 1;
  • more data hotness• Schema management• Works the same across databases
  • rails console• Try out code live• Inspect your data using code
  • testing• Built into rails• Strong testing culture built into ruby
  • servicesgithub.comheroku.comengineyard.comRailsHotline.com
  • Installation
  • • Mac needs XCode first http://developer.apple.com/xcode/• Linux or Mac, use RVM bootstrap http://bit.ly/unixrails• Windows http://railsinstaller.org• Ubuntu on VirtualBox is fun too
  • Test your installrails new kickballappcd kickballappbundlerails server(open a browser to http://localhost:3000)
  • Our project:A League Manager
  • Chapter 2: Data Views
  • Data
  • class Team• name• (id, created_at, updated_at)
  • class Location• name• address• (id, created_at, updated_at)
  • class Game• starts_at• ends_at• location• home_team• away_team• (id, created_at, updated_at)
  • class Game• starts_at• ends_at class Location• location• home_team• away_team• (id, created_at, updated_at)
  • class Game• starts_at• ends_at class Location• location• home_team class Team• away_team• (id, created_at, updated_at)
  • CODE!http://bit.ly/railsbc-code
  • Database Migrations• live in db/migrate• ordered• Abstracted SQL column types• includes id and timestamps by default
  • MORE CODE!
  • RESTful Routes• GET /locations (show all locations)• GET /locations/3 (show one location)• POST /locations (make a location)• PUT /locations/3 (update one location)
  • Can also be nested• GET /locations/3/games (show games for one location)
  • ‘public’ folder• For all static files• Rails looks here first• Offers caching options
  • Views
  • ERB• Like JSP/ASP/PHP but in ruby• lots of helper functions for forms, etc.• layout → view → partials
  • VIEW CODE!
  • ActiveRecord Associations• 1 to 1 (belongs_to - has_one)• 1 to many (belongs_to - has_many)• many to many (has_many :through)
  • Other points• Controllers
  • Chapter 3:User Stories Testing
  • User Stories
  • (pivotal tracker)
  • In order to [value]As a [actor]I want [feature]
  • Players feature?
  • In order to know who is on a teamAs a league managerI want to see a list of players onthe team page
  • Feature: Player listings In order to know who is on a team As a league manager I want to see a list of players on the team page Scenario: listing on a team page Given I am on the teams page When I follow "Ballshevicks" Then I should see "Trotter"
  • CucumberFeature: Player listings In order to know who is on a team As a league manager I want to see a list of players on the team page Scenario: listing on a team page Given I am on the teams page When I follow "Ballshevicks" Then I should see "Trotter"
  • User Storiesas Integration Tests
  • Setting up Cucumber1. Add `group :development, :test` to Gemfile2. Add ‘cucumber-rails’, ‘capybara’ and ‘database_cleaner’ in that group3. Run `bundle`4. Run `rails generate cucumber:install`5. `$EDITOR features/players.feature`
  • undefined local variable or method `node for #<Capybara::Driver::RackTest::Node:...> (NameError) • Comment out line 18 in features/ support/env.rb • cucumber-rails 0.4.0 fixes this, but it’s still in beta
  • CODE(setting it up)
  • Running a scenario1. Put `@wip` above the scenario2. Run `rake cucumber:wip`
  • CODE(running it)
  • Debugging`Then show me the page`requires ‘launchy’ gem`Then debug` (debugger;1)requires ‘ruby-debug’ or ‘ruby-debug19’
  • CODE(debugging it)
  • Building data
  • `$EDITOR features/support/fixtures.rb`Before do  Team.create(:name => "Ballshevicks")end
  • • Any features/support/*.rb gets loaded• `Before` gets run before each Scenario
  • Other Data Options• Load test/fixtures/*.yml• Use the ‘fabrication’ object factory gem
  • CODE(giving it data)
  • Defining Steps When I follow "Show" in the row with "Ballshevicks"When /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|  When %Q|I follow "#{link}" within "tr:contains(#{text})"|end features/step_definitions/table_steps.rb
  • Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular ExpressionWhen /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|  When %Q|I follow "#{link}" within "tr:contains(#{text})"|end features/step_definitions/table_steps.rb
  • Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular Expression Capturing groupsWhen /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|  When %Q|I follow "#{link}" within "tr:contains(#{text})"|end features/step_definitions/table_steps.rb
  • Defining Steps When I follow "Show" in the row with "Ballshevicks" Regular Expression Capturing groupsWhen /^I follow "([^"]*)" in the row with "([^"]*)"$/ do |link, text|  When %Q|I follow "#{link}" within "tr:contains(#{text})"|end features/step_definitions/table_steps.rb Definition in ruby code
  • web_steps.rbGiven I am on the (rake routes) pageWhen I press “button” / follow “link”When I fill in “field” with “value”When I select “option” from “field”When I check “field”Then I should see “text” (within “section”)
  • CODE(assigning teams?)
  • Unit testing
  • Use for direct testing of• Models (test/unit/*.rb)• Helpers (test/unit/helpers/*.rb)• Controllers (test/functional/*.rb)
  • Example: Player#last_nameclass PlayerTest < ActiveSupport::TestCase  test "parses out last name" do    trotter = Player.new(:name => "Trotter Cashion")    assert_equal "Cashion", trotter.last_name  endend (Test First! At least try.)
  • CODE(run and fix it)
  • Chapter 4: Do it!