/
README
153 lines (85 loc) · 3.37 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# 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?