Upload
fay-imogene-hicks
View
213
Download
0
Embed Size (px)
Citation preview
Lecture 10Rails Projects
Lecture 10Rails Projects
Topics Topics
• SaaSSaaS
Readings: Readings: SaaS book Ch 2, 4SaaS book Ch 2, 4
February 24, 2014
CSCE 740 Software Engineering
– 2 – CSCE 740 Spring 2014
SaaS round 2 - SaaS round 2 -
Last TimeLast Time
RAILSRAILS
Fig 2.1 100,000 viewFig 2.1 100,000 view
Client-serverClient-server
HTTP & URIsHTTP & URIs
HTML & CSSHTML & CSS
HAMLHAML
Finish-up Last Lecture SlidesFinish-up Last Lecture Slides
Slides ???Slides ???
New New
Summary of RailsSummary of Rails
HAMLHAML
CucumberCucumber
CapybaraCapybara
Next Time:Next Time:
– 3 – CSCE 740 Spring 2014
Rails Summary from Last timeRails Summary from Last time
9.9. The MVC ArchitectureThe MVC Architecture
10.10. Components of RailsComponents of Rails
11.11. RESTREST
12.12. a New Rails Projecta New Rails Project
13.13. Rails Application DirRails Application Dir
14.14. Rails Appl Directory IIRails Appl Directory II
15.15. Directory: appDirectory: app
16.16. HAML - lightweightHAML - lightweight
17.17. YAML-YAML-human-readable data serialization formatformat
18.18. Configuring a DBConfiguring a DB
19.19. Creating a DBCreating a DB
20.20. Starting WebrickStarting Webrick
21.21. rails generaterails generate
22.22. Setting the Application Setting the Application Home PageHome Page
23.23. Rails ScaffoldingRails Scaffolding
28.28. What’s Next?What’s Next?
29.29. Rails SummaryRails Summary
30.30. Active Record Active Record
31.31. … … CS 169 Saasbook: Fox and Patterson
– 4 – CSCE 740 Spring 2014
Chapter 2 SaaS Architecture ReviewChapter 2 SaaS Architecture Review
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 5 – CSCE 740 Spring 2014
Review Fig 2.3 – URI + HTTPmethodReview Fig 2.3 – URI + HTTPmethod
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 6 – CSCE 740 Spring 2014
Fig 2.4 50,000 ft viewFig 2.4 50,000 ft view
– 7 – CSCE 740 Spring 2014
Fig 2.6 Refining Steps 2 and 3Fig 2.6 Refining Steps 2 and 3
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 8 – CSCE 740 Spring 2014
LampLamp
Early SaaS sites were created using the Perl and Early SaaS sites were created using the Perl and PHP scripting languages, whose PHP scripting languages, whose
availability coincided with the early success of availability coincided with the early success of Linux, an open-source operating system, and Linux, an open-source operating system, and MySQL, an open-source database. MySQL, an open-source database.
Thousands of sites are still powered by the LAMP Thousands of sites are still powered by the LAMP Stack—Linux, Apache, MySQL, and PHP or Perl.Stack—Linux, Apache, MySQL, and PHP or Perl.
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 9 – CSCE 740 Spring 2014
ScalabilityScalability
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 10 – CSCE 740 Spring 2014
Fig 2.8 5,000 ft view Refining MiddlewareFig 2.8 5,000 ft view Refining Middleware
– 11 – CSCE 740 Spring 2014
Architectures for Web AppsArchitectures for Web Apps
Left - page controller SinatraLeft - page controller Sinatra
Center top – front controller J2EE servletsCenter top – front controller J2EE servlets
Center bottom – PHPCenter bottom – PHP
Right – MVC used by railsRight – MVC used by railsSaasbook Fox, Armando; Patterson, David (2014-01-31).
– 12 – CSCE 740 Spring 2014
Fig 2.10 – 5,000 ft viewFig 2.10 – 5,000 ft view
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 13 – CSCE 740 Spring 2014
2.6 500 Feet: Active Record for Models2.6 500 Feet: Active Record for Models
Active Record architectural patternActive Record architectural pattern
a single instance of a model class (in our case, the a single instance of a model class (in our case, the entry for a single movie) corresponds to a single row entry for a single movie) corresponds to a single row in a specific tablein a specific table
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 14 – CSCE 740 Spring 2014
CRUDCRUD
CCreate a new row in the table (representing a new reate a new row in the table (representing a new object), object),
RRead an existing row into a single object instance, ead an existing row into a single object instance,
UUpdate an existing row with new attribute values pdate an existing row with new attribute values from a modified object instance, from a modified object instance,
DDelete a row (destroying the object’s data forever).elete a row (destroying the object’s data forever).
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 15 – CSCE 740 Spring 2014
2.7 500 Feet: Routes, Controllers, and REST2.7 500 Feet: Routes, Controllers, and REST
REST - In 2000, Roy Fielding proposed, in his Ph.D. REST - In 2000, Roy Fielding proposed, in his Ph.D. dissertation, a consistent way to map requests to dissertation, a consistent way to map requests to actions that is particularly well suited to a service-actions that is particularly well suited to a service-oriented architecture.oriented architecture.
identify the various entities manipulated by a Web app identify the various entities manipulated by a Web app as resources, and as resources, and
design the routes so that any HTTP request would design the routes so that any HTTP request would contain all the information necessary to identify both a contain all the information necessary to identify both a particular resource and the action to be performed on particular resource and the action to be performed on it.it.
In Rails, the route mappings are generated by code in In Rails, the route mappings are generated by code in the file config/routes.rb,the file config/routes.rb,
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 16 – CSCE 740 Spring 2014
Fig 2.12 Rake Routes SummaryFig 2.12 Rake Routes Summary
Operation Operation Method & URI Method & URI action action
Index (list) movies Index (list) movies GET /moviesGET /movies index index
Read (show) movie Read (show) movie GET /movies/:id GET /movies/:id showshow
Display fill-in form Display fill-in form GET /movies/new GET /movies/new newnew
Create from filled-in form POST /moviesCreate from filled-in form POST /movies create create
Display form to edit Display form to edit GET /movies/:id/editGET /movies/:id/edit editedit
Update movie Update movie PUT /movies/:id PUT /movies/:id update update
Destroy movie Destroy movie DELETE /movies/:id DELETE /movies/:id destroydestroy
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 17 – CSCE 740 Spring 2014
Fig 2.13 Restful vs nonRestfulFig 2.13 Restful vs nonRestful
Login to site Login to site
• Non-RESTful site - POST /login/dave Non-RESTful site - POST /login/dave
• URI RESTful site - POST /login/dave URI RESTful site - POST /login/dave
Welcome page Welcome page
• Non-RESTful Non-RESTful - GET /welcome - GET /welcome
• URI RESTful URI RESTful - GET /user/301/welcome - GET /user/301/welcome
Add item ID 427 to cart Add item ID 427 to cart
• Non-RESTful Non-RESTful - POST /add/427 - POST /add/427
• URI RESTful URI RESTful - POST /user/301/add/427- POST /user/301/add/427
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 18 – CSCE 740 Spring 2014
View cartView cart
• Non-RESTful Non-RESTful - GET / cart - GET / cart
• URI RESTful URI RESTful - GET /user/301/cart - GET /user/301/cart
CheckoutCheckout
• Non-RESTful Non-RESTful - POST /checkout - POST /checkout
• URI RESTful URI RESTful - POST /user/301/checkout- POST /user/301/checkout
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 19 – CSCE 740 Spring 2014
ELABORATION: REST vs. SOAP vs. WS-*ELABORATION: REST vs. SOAP vs. WS-*SOA standards bodies created committees to develop SOA standards bodies created committees to develop
standards for SOA interoperation.standards for SOA interoperation.
One approach resulted in a collection of elaborate One approach resulted in a collection of elaborate protocols for Web Services including WS-Discovery, protocols for Web Services including WS-Discovery, WS-Description, and others, sometimes collectively WS-Description, and others, sometimes collectively called WS-* and jokingly called “WS-Deathstar” by called WS-* and jokingly called “WS-Deathstar” by David Heinemeier Hansson, the creator of Rails. David Heinemeier Hansson, the creator of Rails.
The competing SOAP standard (Simple Object Access The competing SOAP standard (Simple Object Access Protocol) was a bit simpler but still far more complex Protocol) was a bit simpler but still far more complex than REST. By and large, practicing developers than REST. By and large, practicing developers perceived SOAP and WS-* as overdesigned perceived SOAP and WS-* as overdesigned committee-driven standards burdened by the archaic committee-driven standards burdened by the archaic design stancedesign stance
Saasbook Fox, Armando; Patterson, David (2014-01-31).
– 20 – CSCE 740 Spring 2014
Fig 2.14 500 ft – Template views HAMLFig 2.14 500 ft – Template views HAMLHaml Haml HTML HTML
%br{:clear => ’left’} %br{:clear => ’left’} <br clear=”left”/> <br clear=”left”/>
%p.foo Hello %p.foo Hello <p class=”foo”>Hello</p> <p class=”foo”>Hello</p>
%p#foo Hello %p#foo Hello <p id=”foo”>Hello</p><p id=”foo”>Hello</p>
.foo .foo <div class=”foo”>. . . </div> <div class=”foo”>. . . </div>
#foo.bar #foo.bar <div id=”foo” class=”bar”>. . . </div><div id=”foo” class=”bar”>. . . </div>
Saasbook Fox, Armando; Patterson, David (2014-01-31).