Ruby and Rails, as secret weapon to build your service-oriented apps
Single Page Apps with Breeze and Ruby
description
Transcript of Single Page Apps with Breeze and Ruby
![Page 1: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/1.jpg)
Single Page Apps with
Breeze and Ruby
![Page 2: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/2.jpg)
http://pluralsight.com/training/Courses/TableOfContents/single-page-apps-jumpstart https://github.com/johnpapa/PluralsightSpaJumpStartFinal
John Papa’s Code Camper Jumpstart
![Page 3: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/3.jpg)
Features• Multi-entity model• Navigation properties / cached lookup lists• Projections / partial entities• Change notification• Dirty checking• Validation• Save• Local storage
![Page 4: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/4.jpg)
Keys• Client app is server agnostic (almost)• Ruby on Rails (RoR) server• Straight rails; no breeze.ruby components• “REST” API• Python web server• No MS
![Page 5: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/5.jpg)
Not anti-Microsoft
![Page 6: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/6.jpg)
If it works in Rubyit can work for you
![Page 7: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/7.jpg)
Run it1. Download from GitHub2. Setup install gems and create sample MySQL database
3. Start rails server bundle exec rails s
4. Start client application server python –m http.server
5. Launch in browser http://localhost:8000
~\ccjs_ruby\rails>bundle exec rails s
![Page 8: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/8.jpg)
Demo
![Page 9: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/9.jpg)
Web Server
HTML, JavaScript, CSS, images
![Page 10: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/10.jpg)
Code Tour
![Page 11: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/11.jpg)
RoR Server
![Page 12: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/12.jpg)
RoR Server – Configuration
Locate the My SQL database
![Page 13: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/13.jpg)
RoR Server – ConfigurationBreeze Metadata
![Page 14: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/14.jpg)
RoR Server – Model View Controller
![Page 15: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/15.jpg)
RoR Server – ControllersCross Origin Resource Sharing
![Page 16: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/16.jpg)
RoR Server – Models
![Page 17: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/17.jpg)
RoR Server - ControllersSessions Controller
GET by id
GET all
PUT
POST
DELETE
![Page 18: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/18.jpg)
Sessions Controller – Index (get all)
Partial entity if $select in query
Default sort order is time_slot_idbut client typically wants by ‘timeslot, track, speaker name’
Make speaker available in case sorting on speaker name
Projection (selected fields)
![Page 19: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/19.jpg)
RoR Server – Session Views
![Page 20: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/20.jpg)
RoR Server – Controllers
![Page 21: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/21.jpg)
RoR Server - Views
![Page 22: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/22.jpg)
API Differences
![Page 23: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/23.jpg)
Rails serialization vs JSON.NET serialization
Rails Session
JSON.NET Session
• Rails-style entity property_names
• No $id node property
• $type node property is readable (v. anonymous type)
![Page 24: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/24.jpg)
Rails REST update vs Breeze “save changes”
PUT to resource w/ id=1
Send only the changed values
POST to SaveChanges
Send entire entity
![Page 25: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/25.jpg)
Adjust breeze clientfor Rails API
![Page 26: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/26.jpg)
Configure adapters
Inject with RequireJS
Breeze extension points
![Page 27: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/27.jpg)
AjaxRestInterceptorTweak the breeze ajax adapter to convert OData id-query into a REST URL
e.g., /breeze/Sessions/?$filter=id eq 1 /breeze/Sessions/1
![Page 28: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/28.jpg)
DataServiceAdapterReplace POST to “SaveChanges” with RESTPUT/POST/DELETE to entity type controllers
![Page 29: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/29.jpg)
JsonResultsAdapterIdentify “partial entity” JSON data nodes
![Page 30: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/30.jpg)
NamingConvention Convert property namese.g., timeSlotId time_slot_id
![Page 31: Single Page Apps with Breeze and Ruby](https://reader035.fdocuments.us/reader035/viewer/2022062305/56816293550346895dd30691/html5/thumbnails/31.jpg)
Thank you, RubyTribe