enter the app era with ruby on rails
TRANSCRIPT
![Page 1: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/1.jpg)
Enter the App Era with Ruby on Rails
@matteocollina
![Page 3: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/3.jpg)
Matteo Collina
Software Engineer
@matteocollina
matteocollina.com
![Page 4: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/4.jpg)
www.mavigex.comwww.wemobi.it
![Page 5: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/5.jpg)
How is built an App?
http://www.flickr.com/photos/dschulian/3173331821/
![Page 11: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/11.jpg)
Icons by Fasticon
Code Run ServerI need to serve my data to
Web and Mobile Apps
![Page 12: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/12.jpg)
We need an API
![Page 13: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/13.jpg)
We need an API
Who has APIs?
![Page 14: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/14.jpg)
Who has APIs?
![Page 15: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/15.jpg)
Who has APIs?
![Page 16: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/16.jpg)
Who has APIs?
And many many others..
![Page 17: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/17.jpg)
We will develop an API
![Page 18: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/18.jpg)
http://www.flickr.com/photos/oneaustin/1261907803
We need to be fast!
![Page 19: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/19.jpg)
http://www.flickr.com/photos/oneaustin/1261907803
We have just twenty minutes
![Page 20: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/20.jpg)
What do we want to build? http://www.flickr.com/photos/oberazzi/318947873/
![Page 21: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/21.jpg)
Another tool for nerds?
http://www.flickr.com/photos/eyesontheroad/2260731457/
![Page 22: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/22.jpg)
Another Todo List?
http://www.flickr.com/photos/eyesontheroad/2260731457/
![Page 23: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/23.jpg)
Enter MCDo.http://github.com/mcollina/mcdo
![Page 24: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/24.jpg)
Enter MCDo.
The First Todo Listdelivered as a REST API
![Page 25: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/25.jpg)
The First Todo Listdelivered as a REST API
![Page 26: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/26.jpg)
Signup APIhttp://github.com/mcollina/mcdo
![Page 27: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/27.jpg)
Signup APIFeature: Signup API As a MCDO developer In order to develop apps I want to register new users
Scenario: Succesful signup When I call "/users.json" in POST with: """ { "user": { "email": "[email protected]", "password": "abcde", "password_confirmation": "abcde" } } """ Then the JSON should be: """ { "id": 1, "email": "[email protected]" } """
![Page 28: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/28.jpg)
Signup API
Scenario: signup fails with a wrong password_confirmation When I call "/users.json" in POST with: """ { "user": { "email": "[email protected]", "password": "abcde", "password_confirmation": "abcde1" } } """ Then the JSON should be: """ { "errors": { "password": ["doesn't match confirmation"] } } """
![Page 29: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/29.jpg)
How?
![Page 30: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/30.jpg)
How?
Ruby on Rails
Cucumber
RSpec
JSON-spec
![Page 31: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/31.jpg)
How?
Ruby on Rails
Cucumber
RSpec
JSON-spec
Let’s see some code!
![Page 32: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/32.jpg)
Login APIhttp://github.com/mcollina/mcdo
![Page 33: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/33.jpg)
Login APIFeature: Login API As a MCDO developer In order to develop apps I want to login with an existing user
Background: Given there is the following user: | email | password | password_confirmation | | [email protected] | aa | aa |
Scenario: Succesful login When I call "/session.json" in POST with: """ { "email": "[email protected]", "password": "aa" } """ Then the JSON should be: """ { "status": "authenticated" } """
![Page 34: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/34.jpg)
Login API Scenario: Failed login When I call "/session.json" in POST with: """ { "email": "[email protected]", "password": "bb" } """ Then the JSON should be: """ { "status": "not authenticated" } """
![Page 35: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/35.jpg)
Login APIScenario: Validating an active session Given I call "/session.json" in POST with: """ { "email": "[email protected]", "password": "aa" } """ When I call "/session.json" in GET Then the JSON should be: """ { "status": "authenticated" } """
![Page 36: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/36.jpg)
Login APIScenario: Validating an active session Given I call "/session.json" in POST with: """ { "email": "[email protected]", "password": "aa" } """ When I call "/session.json" in GET Then the JSON should be: """ { "status": "authenticated" } """
Let’s see some code!
![Page 37: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/37.jpg)
Lists APIhttp://github.com/mcollina/mcdo
![Page 38: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/38.jpg)
Lists APIFeature: Lists API As a MCDO developer In order to develop apps I want to manage a user's lists
Background: Given I login succesfully with user "[email protected]"
Scenario: Default lists When I call "/lists.json" in GET Then the JSON should be: """ { "lists": [{ "id": 1, "name": "Personal", "link": "http://www.example.com/lists/1", "items_link": "http://www.example.com/lists/1/items" }] } """
![Page 39: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/39.jpg)
Lists API
Scenario: Creating a list When I call "/lists.json" in POST with: """ { "list": { "name": "foobar" } } """ Then the JSON should be: """ { "name": "foobar", "items_link": "http://www.example.com/lists/1/items" } """
![Page 40: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/40.jpg)
Lists API Scenario: Creating a list should add it to the index Given I call "/lists.json" in POST with: """ { "list": { "name": "foobar" } } """ When I call "/lists.json" in GET Then the JSON should be: """ { "lists": [{ "id": 2, "name": "foobar", "link": "http://www.example.com/lists/2", "items_link": "http://www.example.com/lists/2/items" }, { "id": 1, "name": "Personal", "link": "http://www.example.com/lists/1", "items_link": "http://www.example.com/lists/1/items" }] } """
![Page 41: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/41.jpg)
Lists API Scenario: Removing a list (and the index is empty) Given I call "/lists/1.json" in DELETE When I call "/lists.json" Then the JSON should be: """ { "lists": [] } """
Scenario: Updating a list's name When I call "/lists/1.json" in PUT with: """ { "list": { "name": "foobar" } } """ Then the JSON should be: """ { "name": "foobar", "items_link": "http://www.example.com/lists/1/items" } """
![Page 42: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/42.jpg)
Scenario: Removing a list (and the index is empty) Given I call "/lists/1.json" in DELETE When I call "/lists.json" Then the JSON should be: """ { "lists": [] } """
Scenario: Updating a list's name When I call "/lists/1.json" in PUT with: """ { "list": { "name": "foobar" } } """ Then the JSON should be: """ { "name": "foobar", "items_link": "http://www.example.com/lists/1/items" } """
Lists API
Let’s see some code!
![Page 43: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/43.jpg)
Items APIhttp://github.com/mcollina/mcdo
![Page 44: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/44.jpg)
Items API
Feature: Manage a list's items As a developer In order to manipulate the list's item I want to access them through APIs
Background: Given I login succesfully with user "[email protected]"
Scenario: Default items When I call "/lists/1/items.json" in GET Then the JSON should be: """ { "items": [{ "name": "Insert your items!", "position": 0 }], "list_link": "http://www.example.com/lists/1" } """
![Page 45: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/45.jpg)
Items API Scenario: Moving an element to the top Given I call "/lists/1/items.json" in POST with: ... And I call "/lists/1/items.json" in POST with: ... When I call "/lists/1/items/2/move.json" in PUT with: """ { "position": 0 } """ Then the JSON should be: """ { "items": [{ "name": "b", "position": 0 }, { "name": "Insert your items!", "position": 1 }, { "name": "c", "position": 2 }], "list_link": "http://www.example.com/lists/1" } """
![Page 46: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/46.jpg)
Items API Scenario: Moving an element to the top Given I call "/lists/1/items.json" in POST with: ... And I call "/lists/1/items.json" in POST with: ... When I call "/lists/1/items/2/move.json" in PUT with: """ { "position": 0 } """ Then the JSON should be: """ { "items": [{ "name": "b", "position": 0 }, { "name": "Insert your items!", "position": 1 }, { "name": "c", "position": 2 }], "list_link": "http://www.example.com/lists/1" } """
Let’s see some code!
![Page 47: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/47.jpg)
Do we need an admin panel?
![Page 48: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/48.jpg)
Do we need an admin panel?
![Page 49: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/49.jpg)
Do we need an admin panel?
Put in your Gemfile:
gem 'activeadmin'gem 'meta_search', '>= 1.1.0.pre'
Then run:
$ bundle install$ rails g active_admin:install$ rails g active_admin:resource users$ rails g active_admin:resource lists$ rails g active_admin:resource items$ rake db:migrate
![Page 50: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/50.jpg)
Do we need an admin panel?
Put in your Gemfile:
gem 'activeadmin'gem 'meta_search', '>= 1.1.0.pre'
Then run:
$ bundle install$ rails g active_admin:install$ rails g active_admin:resource users$ rails g active_admin:resource lists$ rails g active_admin:resource items$ rake db:migrate
Let’s see some code!
![Page 51: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/51.jpg)
Build a JS App!
![Page 52: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/52.jpg)
Build a JS App!
Backbone.js: MVC in the browser
Rails asset pipeline concatenate and minifies our JS automatically
We can even write our app in CoffeeScript: it works out of the box.
![Page 53: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/53.jpg)
Build a JS App!
Backbone.js: MVC in the browser
Rails asset pipeline concatenate and minifies our JS automatically
We can even write our app in CoffeeScript: it works out of the box.
to the code.. again?
![Page 54: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/54.jpg)
http://www.flickr.com/photos/oneaustin/1261907803
![Page 55: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/55.jpg)
http://www.flickr.com/photos/oneaustin/1261907803
We are late,the #codemotion
crew are kicking me out
![Page 56: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/56.jpg)
TL;DR
http://www.flickr.com/photos/evilaugust/3307382858
![Page 57: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/57.jpg)
TL;DR
Mobile Apps need an API
Ruby on Rails is good for writing APIs
You can build nice admin interfaces with ActiveAdmin
You can craft Javascript Apps easily using the asset pipeline.
![Page 59: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/59.jpg)
Any Questions?
![Page 60: Enter the app era with ruby on rails](https://reader033.vdocuments.net/reader033/viewer/2022052900/5562d232d8b42a6c498b4c01/html5/thumbnails/60.jpg)
Thank You!