Author
vandung
View
212
Download
0
Embed Size (px)
Rails 2.0
1
Barry Burd
This slide presentation 2008 Barry Burd
Copyrights for Ruby, Rails and other material are held by their
respective owners.
Install Ruby and Rails
Ruby - http://www.ruby-lang.org/en/downloads/
Rails -
2008 Barry Burd 2
Install SQLite
http://www.sqlite.org/download.html
2008 Barry Burd 3
Copy the uncompressed files to your ruby\bin directory
Install SQLite (continued)
2008 Barry Burd 4
Install the Aptana IDE
You need the Java Runtime -
http://java.sun.com/javase/downloads/index.jsp
Aptana - http://www.aptana.com/download/index.php
2008 Barry Burd 5
Install the
RadRails plugin
within Aptana
2008 Barry Burd 6
Configure RadRails
2008 Barry Burd 7
Configure RadRails
2008 Barry Burd 8
Configure RadRails
2008 Barry Burd 9
The Aptana IDE
Based on Eclipse
View
Editor
Part
Area
Perspective
2008 Barry Burd 10
Ruby
Pers
2008 Barry Burd11
spective
Rails
Per
2008 Barry Burd 12
rspective
Data
Per
2008 Barry Burd 13
rspective
Debug
Per
2008 Barry Burd 14
rspective
Watch a movie...
http://www.burdbrain.com/RubyOnRails/Rails2.wmv
2008 Barry Burd 15
RadRails Perspective
2008 Barry Burd 16
Create a new Rails Project
2008 Barry Burd 17
Name the project
2008 Barry Burd18
Rails creates
folders and files
2008 Barry Burd 19
Create a database
2008 Barry Burd 20
Generate a scaffold
2008 Barry Burd 21
Migrate the databaseCreate table(s) and column(s)
2008 Barry Burd 22
Start the projects Web server
2008 Barry Burd 23
Visit the Web servers Welcome page
2008 Barry Burd 24
Visit the list page
2008 Barry Burd 25
Add a new record
2008 Barry Burd 26
2008 Barry Burd 27
Show an existing record
2008 Barry Burd 28
Edit an existing record
2008 Barry Burd 29
Several types
of fields
2008 Barry Burd30
The Migration FileBookstore\db\migrate\001_create_books.rb
2008 Barry Burd 31
Bookstore\config\database.yml
2008 Barry Burd 32
The Model CodeBookstore\app\models\book.rb
2008 Barry Burd 33
The Controller CodeBookstore\app\controllers\books_controller.rb
"if the client wants HTML in
response to this action, just
respond as we would have
before, but if the client wants
XML, return them the list of
people in XML format." (Rails
determines the desired
response format from the
HTTP Accept header submitted
2008 Barry Burd 34
HTTP Accept header submitted
by the client.)
Let the instance variable (the attribute) @book be
the record you get when
you look for a record
whose id matches the
incoming id parameter.
The Controller CodeBookstore\app\controllers\books_controller.rb
2008 Barry Burd 35
The Controller CodeBookstore\app\controllers\books_controller.rb
2008 Barry Burd 36
The Controller CodeBookstore\app\controllers\books_controller.rb
2008 Barry Burd
The Index PageBookstore\app\views\books\index.html.erb
2008 Barry Burd
View Source
View Source
xml:lang="en" lang="en">
Books: index
2008 Barry Burd 39
View Source
Listing books
Title
IsbnIsbn
Ruby on Rails For Dummies
12233355566622444
Show
Edit
View Source
Listing books
Title
IsbnIsbn
Ruby on Rails For Dummies
12233355566622444
Show
Edit
The Edit PageBookstore\app\views\books\edit.html.erb
2008 Barry Burd 42
The New PageBookstore\app\views\books\new.html.erb
2008 Barry Burd 43
The Show PageBookstore\app\views\books\show.html.erb
2008 Barry Burd 44
Fine tuning a Web application
2008 Barry Burd 45
Adding validation to the model code
2008 Barry Burd 46
Attempting to create a new record, but...
2008 Barry Burd 47
...validation errors
2008 Barry Burd 48
The views code takes
notice of errors
2008 Barry Burd 49
Rails has several validates methods
50 2008 Barry Burd
Relationships between tables
2008 Barry Burd 51
Bookstore\db\migrate\002_create_reviews.rb
2008 Barry Burd 52
Run the most recent migration
2008 Barry Burd 53
Bookstore\app\models\book.rb
2008 Barry Burd 54
Bookstore\app\models\review.rb
2008 Barry Burd 55
The Rails Console
2008 Barry Burd 56
2008 Barry Burd 57
Add code toBookstore\app\views\books\show.html.erb
2008 Barry Burd 58
Add a method toBookstore\app\controllers\books_controller.rb
2008 Barry Burd 59
2008 Barry Burd 60
2008 Barry Burd 61