austinmoore / ttalk-2009-06-18

demo app from the namics t.talk on Thursday, June 18th, 2009

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

# Preparation

# Uninstall the will_paginate gem so that the audience can see what 'sudo rake gems:install' really does (this causes an error if the gem does not exist locally)
sudo gem uninstall mislav-will_paginate



# Ruby - Getting Started

# I started with ruby by learning the Rails framework.  I come from the java world.  I can tell you the java equivalent for what I'm showing in ruby.

# Any questions -> ask right away.

# In the next 20 minutes we'll learn some ruby by...

# creating a basic rails application
# generating scaffold code
# extend the generated code (with pagination)

# if time remaining -> deploy the app live

# If you want to get started with ruby/rails visit know.namics.com and type rails + windows for this tutorial

# In terminal

cd Desktop

rails ttalk-app

cd ttalk-app

script/generate scaffold patient name:string surname:string birthday:date weight:integer

rake db:migrate

script/server

# Open http://localhost:3000/patients

# Create a new patient and edit it.  View all patients.

# Open directory in RubyMine
# Show db/migrate/*_create_patients.rb

# Rails is a MVC framework...
# Show app/models/patient.rb
# Show app/controllers/patients_controller.rb
# Show app/views/patients/index.html.erb

# Now we want to extend patients with pagination

script/console

Patient.create(:name => "Bob", :surname => "Barker", :birthday => 20.years.ago, :weight => 65)

20.times {
Patient.create(:name => "Bob", :surname => "Barker", :birthday => 20.years.ago, :weight => 65)
}

# Refresh the page in browser. Now I have my patients.  Let's add the pagination.

# Won't do it by hand.  That would be tiresome.

# Switch to Browser -> Google "ruby toobox" -> Open ruby toolbox site

# Navigate to "pagination" category

# Open "will_paginate" page

# Switch to RubyMine

# add will_paginate gem to environment.rb

config.gem 'mislav-will_paginate', :version => '~> 2.3.8', :lib => 'will_paginate', :source => 'http://gems.github.com'

# Switch to Terminal

gem list mislav

# gem needs to be installed locally.  Ask rails to install all of the gems the project needs.
sudo rake gems:install

# Now we have it
gem list mislav

# Switch to RubyMine -> patient.rb -> Change call to Patient.all to ...

Patient.paginate :per_page => 5, :page => params[:page], :order => 'updated_at DESC'

# Start up server in IDE

# Switch to Browser and refresh -> Now only 5 patients are displayed

# Now we need to update the view so we can navigate through the pages.

# Switch to RubyMine -> index.html.erb -> Add pagination navigation

<%= will_paginate @patients %>

# Switch to Browser and refresh -> pagination navigation is displayed

# By changing only 3 lines of code we have full functioning pagination.  Wow.



# Check time.  If time remaining, show deployment to heroku

# Switch to Terminal

git init

touch .gitignore

touch .gems

# Copy following to .gitignore

.idea
*.iml
*.ipr
*.iws
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
db/schema.rb

# Copy following to .gems

mislav-will_paginate  --version ">=2.3.8" --source "http://gems.github.com"

# Switch to Terminal

git add .

git commit -m "initial commit"

gem list hero

heroku create austinttalk

git push heroku master

heroku rake db:migrate

heroku console

20.times { Patient.create(:name => "Bob", :surname => "Barker", :birthday => 20.years.ago, :weight => 65) }

# Switch to Browser -> http://austinttalk.heroku.com

# Questions?

About

demo app from the namics t.talk on Thursday, June 18th, 2009


Languages

Language:Ruby 99.2%Language:JavaScript 0.8%