Ruby on Rails 3 Day BC

Post on 01-Sep-2014

363 views 1 download

Tags:

description

NIRD Ruby on Rails 3 day Rails BootCamp

Transcript of Ruby on Rails 3 Day BC

Ruby on Rails3-Day BootCamp

Introductions

Name Coding Experience What would you like to learn?

Curriculum

RoR ToolsetRails Walk-ThroughGems and DeploymentFull Apps and Ruby inside Rails

ScheduleTimes Day 1 Day 2 Day3

9am - 10:30 Tools RubyToolBox BootStrap Break

10:45 - 12 Scaffold and Views Cucumber RailsApps and

Hobo / SpreeLunch

1pm - 2:30 Routes and Controllers Devise Calculator

Break

2:45 - 4:30 Models and Testing I18N and Haml Translator

Learning Goals

Basic RailsCommon Patterns and PracticesWhere to go for help

Learning Path

ExperimentationTest First TeachingAsk QuestionsResources for finding answers

Structure

Explanation (me talking)Demonstration (me typing)Experimentation (in-class coding)Questions

RoR ToolsRVM / Pik / Jewelry Box / Rb.EnvGit / Github / HerokuSublime / Vi / RubyMineRubyGems / RubyToolboxTesting / RSpec / CucumberTerminal / irb / Rails Console

RoR ResourcesRailsGuides - guides.rubyonrails.orgRails API - api.rubyonrails.orgRubyDoc - ruby-doc.orgRailsCasts - railscasts.comGithub ReadMeRuby ToolBox - www.ruby-toolbox.com

Ruby vs. RailsRuby is the Language -

developed 1993 Yukihiro Matsumoto “Matz”

Rails is the Framework - developed 2004 David Heinemeier Hansson “DHH”

The Ruby Way Written in CInfluenced by SmallTalk & PearlRuby is for PeopleMINSWANOSS (Open Source Software)RubyGems

The Rails Way

Opinionated SoftwareConvention over ConfigurationDRY (Don’t Repeat Yourself)TDD (Test Driven Development)Less Code, More Productivity

ToolsCommand LineRuby / RubyGemsRailsSource Control - GitIDEDeployment - Heroku

Command Line

Command Prompt (CLI)Mac: Terminal, iTerm, etc...Unix: bash, zsh, csh, etc....Windows: Command Prompt w/ Ruby on Rails

Ruby

Ruby -v1.9.2, 1.9.3, 2.0.0 (1.8.7)

gem listBundler, Rake, rubygems, etc...

RVMRuby Version Manager

rvm listrvm uservm gemset list

rvm.io

Ruby VersionsMRI, YARV, Standard Library, C-RubyJRuby - JavaRubinius - Pure RubyMagLev - SmallTalkMacRuby - Objective-CIronRuby - C# (for .Net)

Rails

Rails -v2.0-3, 3.0-2, 4.0

RVM DemoGemset for Rails 4

rvm use --create 2.0.0@rails4gem install rails --version 4.0.0.beta1 mkdir rvm_testcd rvm_testrvm --rvmrc --create

Git

which gitgit --version

Git

Source Control SystemTimeline, Track ChangesBranching and MergingCode Safety

Git Commandsgit clone / initgit statusgit add / rmgit commitgit pushgit log

Git Remotes

GitHub - www.github.comHeroku - www.heroku.com

Git Help

Git Site - git-scm.comGit Immersion - gitimmersion.comGitHub Help - help.github.com

Git Demomkdir git_testcd git_testgit inittouch test_file.txtgit statusgit add .git commit -m “add a file”git status

Git Democd ..git clone git_test/.git clone_testcd clone_testlsgit remote -vtouch clone.txtgit commit -am “add another file”git push

Editor

Sublime Text 2 / TextMateRubyMineKomodoEditEclipseVi / Vim / Emacs

Sublime Text 2

Command line aliasWin: doskey subl="C:\Program Files\Sublime Text 2\sublime_text.exe" $*

Mac: ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl

Linux: sudo ln -s /opt/SublimeText2/sublime_text /usr/bin/subl

How to Open a folder

BREAK!

10-15 minutes

Rails

New Rails AppModify the HomePageScaffoldMVCLayers

Create a New App

rails Shows Options

rails new <app_name> --options

Create a Class Management App

We want an app to manage Students, Classes, and Teachersrails new class_mngmt

The Application Directory

The Root of our App: Rails rootEntire App in one directory!

Run the App

cd class_mngmtrails

see rails commandsrails server

Save a Baseline with git

git initgit add .git commit -m “add a bare rails app to track changes”

Modify the HomePage

public/index.htmlpublic folder contains static content

Scaffolding

rails generatesee the generators

rails g scaffold Student full_name age:integer bio:text title

MVC

BrowserBrowserRequestRequest

ControllerController

ModelModel

DatabaseDatabase

ViewView

ResponseResponse

Shorten Bio Demo

Shorten the bio on the view pageAdd a read more link

Helpers

Presentation LogicPresenter PatternRuby Module - Included on all viewsMethod DefinitionsHelp generate html

View Exercise

On the main Student pageChange the Listing Students toShow only the Full Name and titleHave the Full Name link to the view pageRemove the view link

Lunch!

12pm - 1pm