Pourquoi Ruby on Rails ça déchire ?

Simon Courtois
Simon CourtoisCTO Founder at PDFMonkey
Simon Courtois - @happynoff
www.tinci.fr
Ruby on Rails
Why does it rock?
www.tinci.fr
Web
Development
Software
Development
X_
Consulting &
Support
@tincihq
www.tinci.fr
M V C
www.tinci.fr
Model View Controller
www.tinci.fr
O R M
www.tinci.fr
Object Relational Mapping
www.tinci.fr
Active Record
articles
id title body
1 hello world This is a body
# app/models/article.rb
class Article < ActiveRecord::Base
end
!
article = Article.first
!
article.title
#=> "hello world"
www.tinci.fr
Active Record
articles
id title body published
1 hello world This is a body 1
2 other art. Not published 0
articles = Article.where(published: 1)
!
articles.count
#=> 1
www.tinci.fr
Conventions
Configuration
www.tinci.fr
Active Record
articles
id title body author_id
1 ... ... 1
authors
id name
1 John Doe
# app/models/article.rb
class Article < ActiveRec...
belongs_to :author
end
!
# app/models/author.rb
class Author < ActiveRec...
has_many :articles
end
!
article = Article.first
!
article.author.name
#=> “John Doe”
www.tinci.fr
Active Record
MySQL
PostgreSQL
SQLite
…
www.tinci.fr
Routing
# app/controller/hello_controller.rb
class HelloController < ApplicationController
def index
@name = params[:name]
end
end
http://example.com/hello/John
# config/routes.rb
get "hello/:name" => "hello#index"
URL
HTTP verb
controller
controller’s action
parameter
www.tinci.fr
Views
# app/controller/hello_controller.rb
class HelloController < ApplicationController
def index
@name = params[:name]
end
end
# app/views/hello/index.html.erb
Hello <%= @name %>
Conventions !
www.tinci.fr
Helpers
# app/views/articles/index.html.erb
<%= @articles.each do |article| %>
<p><%= link_to article.title, article %></p>
<% end %>
# app/controller/articles_controller.rb
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
end
<p><a href="/articles/1">hello world</a></p>
www.tinci.fr
Helpers
# app/controller/articles_controller.rb
class ArticlesController < ApplicationController
def new
@article = Article.new
end
end
<%= form_for @article do |f| %>
<p><%= f.label :title, "Title" %><br />
<%= f.text_field :title %></p>
!
<p><%= f.label :body, "Body" %><br />
<%= f.text_area :body %></p>
!
<p><%= f.submit %></p>
<% end %>
Title
Body
Create Article
www.tinci.fr
Railties
$ rake routes
GET /hello/:name { :controller => "hello", :action => "index" }
$ rails server
Starts a web server listening on http://localhost:3000/
$ rails console
Starts an interactive console in the application context
>> Article.first.title!
#=> "hello world"
www.tinci.fr
Generators
$ rails generate model author name:string
invoke active_record	

create db/migrate/20120108151543_create_authors.rb	

create app/models/author.rb
instructions to create the authors table
the Author model
www.tinci.fr
Generators
$ rails g scaffold author name:string
create db/migrate/20120108152723_create_authors.rb	

create app/models/author.rb	

!
route resources :authors	

!
create app/controllers/authors_controller.rb	

!
create app/views/authors/index.html.erb	

create app/views/authors/edit.html.erb	

create app/views/authors/show.html.erb	

create app/views/authors/new.html.erb	

create app/views/authors/_form.html.erb	

!
create public/stylesheets/scaffold.css
model
routes
controller
views
default CSS
www.tinci.fr
Generators
# config/routes.rb
resources :authors
authors
 
 GET
 
 /authors

 
 
 { action: index controller: authors }
author
 
 GET
 
 /authors/:id

 
 { action: show controller: authors }
new_author
GET
 
 /authors/new
 
 { action: new controller: authors }

 
 
 
 POST
 
 /authors

 
 
 { action: create controller: authors }
edit_author
GET
 
 /authors/:id/edit
 { action: edit controller: authors }

 
 
 
 PATCH
 /authors/:id

 
 { action: update controller: authors }

 
 
 
 PUT
 
 /authors/:id

 
 { action: update controller: authors }

 
 
 
 DELETE
 /authors/:id

 
 { action: destroy controller: authors }
<%= link_to "All authors", authors_path %>
<%= link_to "Edit", edit_author_path(@author) %>
www.tinci.fr
Generators
www.tinci.fr
Generators
www.tinci.fr
Generators
www.tinci.fr
Generators
www.tinci.fr
Generators
www.tinci.fr
Generators
www.tinci.fr
Generators
www.tinci.fr
Generators
www.tinci.fr
ActiveSupport little additions
1.kilobytes! #=> 1024!
!
!
3.days.ago!! #=> Tue, 24 Jun 2014 09:44:47 UTC +00:00!
!
!
"héhé test".parameterize! #=> "hehe-test"!
!
!
“article”.pluralize!! ! ! #=> "articles"
www.tinci.fr
Extensibility
Thanks to gems
www.tinci.fr
Views and forms
<%= form_for @article do |f| %>
<p><%= f.label :title, "Title" %><br />
<%= f.text_field :title %></p>
!
<p><%= f.label :body, "Body" %><br />
<%= f.text_area :body %></p>
!
<p><%= f.submit %></p>
<% end %>
= simple_form_for @article do |f|

 = f.input :title

 = f.input :body

 = f.submit
slim + simple_form
www.tinci.fr
And many more
Mongoid
Kaminari
Carrierwave
Active Admin
MongoDB
Pagination
File upload
Administration interface
www.tinci.fr
Who is using Rails?
Twitter
Basecamp
Github
Groupon
US Yellow Pages
Shopify
http://rubyonrails.org/applications
www.tinci.fr
Resources
rubyonrails.org Official website
tutorials.jumpstartlab.com/topics Very complete tutorial
railsforzombies.org Interactive tutorial
railstutorial.org/book Free online book
#rubyonrails.fr French IRC channel
www.tinci.fr
Questions?
www.tinci.fr
Thanks!
1 of 35

Recommended

Introduction à Ruby by
Introduction à RubyIntroduction à Ruby
Introduction à RubyMicrosoft
421 views35 slides
Consume RESTful APIs with $resource and Restangular by
Consume RESTful APIs with $resource and RestangularConsume RESTful APIs with $resource and Restangular
Consume RESTful APIs with $resource and RestangularJohn Schmidt
682 views62 slides
RubyMotion by
RubyMotionRubyMotion
RubyMotionMark
2.4K views76 slides
INTERFACE by apidays_Automating style guides for REST, gRPC, or GraphQL by Ph... by
INTERFACE by apidays_Automating style guides for REST, gRPC, or GraphQL by Ph...INTERFACE by apidays_Automating style guides for REST, gRPC, or GraphQL by Ph...
INTERFACE by apidays_Automating style guides for REST, gRPC, or GraphQL by Ph...apidays
641 views36 slides
Designing and developing mobile web applications with Mockup, Sencha Touch an... by
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Matteo Collina
6.9K views34 slides
Protocols promised-land-2 by
Protocols promised-land-2Protocols promised-land-2
Protocols promised-land-2Michele Titolo
329 views51 slides

More Related Content

What's hot

Oro meetup #4 by
Oro meetup #4Oro meetup #4
Oro meetup #4Oleg Zinchenko
417 views16 slides
RSpec by
RSpecRSpec
RSpecMarco Otte-Witte
1K views32 slides
What's new in iOS9 by
What's new in iOS9What's new in iOS9
What's new in iOS9CocoaHeads France
3.6K views38 slides
Excellent by
ExcellentExcellent
ExcellentMarco Otte-Witte
623 views15 slides
Crafting Quality PHP Applications (Bucharest Tech Week 2017) by
Crafting Quality PHP Applications (Bucharest Tech Week 2017)Crafting Quality PHP Applications (Bucharest Tech Week 2017)
Crafting Quality PHP Applications (Bucharest Tech Week 2017)James Titcumb
159 views105 slides
Introduction to JQuery by
Introduction to JQueryIntroduction to JQuery
Introduction to JQueryMobME Technical
1.1K views16 slides

What's hot(11)

Similar to Pourquoi Ruby on Rails ça déchire ?

RoR 101: Session 2 by
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2Rory Gianni
813 views38 slides
Rails for Beginners - Le Wagon by
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le WagonAlex Benoit
147 views97 slides
Pourquoi ruby et rails déchirent by
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirentNicolas Ledez
307 views50 slides
Rails::Engine by
Rails::EngineRails::Engine
Rails::EngineFlavian Missi
800 views17 slides
Supa fast Ruby + Rails by
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + RailsJean-Baptiste Feldis
1.1K views41 slides
Be happy with Ruby on Rails - CEUNSP Itu by
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuLucas Renan
535 views42 slides

Similar to Pourquoi Ruby on Rails ça déchire ?(20)

RoR 101: Session 2 by Rory Gianni
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
Rory Gianni813 views
Rails for Beginners - Le Wagon by Alex Benoit
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
Alex Benoit147 views
Pourquoi ruby et rails déchirent by Nicolas Ledez
Pourquoi ruby et rails déchirentPourquoi ruby et rails déchirent
Pourquoi ruby et rails déchirent
Nicolas Ledez307 views
Be happy with Ruby on Rails - CEUNSP Itu by Lucas Renan
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan535 views
Ember.js Meetup Brussels 31/10/2013 by Hstry
Ember.js Meetup Brussels 31/10/2013Ember.js Meetup Brussels 31/10/2013
Ember.js Meetup Brussels 31/10/2013
Hstry1.2K views
Getting Started with Rails by Basayel Said
Getting Started with RailsGetting Started with Rails
Getting Started with Rails
Basayel Said534 views
Rails antipattern-public by Chul Ju Hong
Rails antipattern-publicRails antipattern-public
Rails antipattern-public
Chul Ju Hong1.6K views
Ruby on Rails introduction by Tran Hung
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
Tran Hung196 views
Introduction To Ruby On Rails by Steve Keener
Introduction To Ruby On RailsIntroduction To Ruby On Rails
Introduction To Ruby On Rails
Steve Keener1.1K views
Building Single Page Application (SPA) with Symfony2 and AngularJS by Antonio Peric-Mazar
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
Ruby on Rails + AngularJS + Twitter Bootstrap by Marcio Marinho
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
Marcio Marinho3K views
Trailblazer Introduction by Nick Sutterer by Pivorak MeetUp
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick Sutterer
Pivorak MeetUp983 views
Introduction to Rails - presented by Arman Ortega by arman o
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
arman o522 views
Rails MVC by Sergiy Koshovyi by Pivorak MeetUp
Rails MVC by Sergiy KoshovyiRails MVC by Sergiy Koshovyi
Rails MVC by Sergiy Koshovyi
Pivorak MeetUp236 views
Introduction to Ruby on Rails by Alessandro DS
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Alessandro DS612 views
Graphql + Symfony | Александр Демченко | CODEiD by CODEiD PHP Community
Graphql + Symfony | Александр Демченко | CODEiDGraphql + Symfony | Александр Демченко | CODEiD
Graphql + Symfony | Александр Демченко | CODEiD

More from Simon Courtois

Conseils pour un lancement Product Hunt réussi by
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussiSimon Courtois
72 views28 slides
Organize your assets with Rails by
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with RailsSimon Courtois
761 views51 slides
Speed your Rails app creation with templates by
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templatesSimon Courtois
783 views25 slides
Dependency sorting in Ruby with TSort by
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSortSimon Courtois
942 views16 slides
How Unidecoder Transliterates UTF-8 to ASCII by
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCIISimon Courtois
782 views34 slides
Get Slim! by
Get Slim!Get Slim!
Get Slim!Simon Courtois
2.2K views23 slides

More from Simon Courtois(16)

Conseils pour un lancement Product Hunt réussi by Simon Courtois
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussi
Simon Courtois72 views
Organize your assets with Rails by Simon Courtois
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with Rails
Simon Courtois761 views
Speed your Rails app creation with templates by Simon Courtois
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templates
Simon Courtois783 views
Dependency sorting in Ruby with TSort by Simon Courtois
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSort
Simon Courtois942 views
How Unidecoder Transliterates UTF-8 to ASCII by Simon Courtois
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCII
Simon Courtois782 views
Multi tenant/lang application with Ruby on Rails by Simon Courtois
Multi tenant/lang application with Ruby on RailsMulti tenant/lang application with Ruby on Rails
Multi tenant/lang application with Ruby on Rails
Simon Courtois1.7K views
REST with Her (and let Her take care of the REST) by Simon Courtois
REST with Her (and let Her take care of the REST)REST with Her (and let Her take care of the REST)
REST with Her (and let Her take care of the REST)
Simon Courtois3.2K views

Recently uploaded

TriStar Gold- Corporate Presentation - December 2023 by
TriStar Gold- Corporate Presentation - December 2023TriStar Gold- Corporate Presentation - December 2023
TriStar Gold- Corporate Presentation - December 2023Adnet Communications
38 views14 slides
supplyfied .pdf by
supplyfied .pdfsupplyfied .pdf
supplyfied .pdfValueBusiness
19 views11 slides
Market Efficiency.pptx by
Market Efficiency.pptxMarket Efficiency.pptx
Market Efficiency.pptxRavindra Nath Shukla
22 views25 slides
Jeremy Hunt's letter to Nausicaa Delfas by
Jeremy Hunt's letter to Nausicaa DelfasJeremy Hunt's letter to Nausicaa Delfas
Jeremy Hunt's letter to Nausicaa DelfasHenry Tapper
516 views2 slides
Debt Watch | ICICI Prudential Mutual Fund by
Debt Watch | ICICI Prudential Mutual FundDebt Watch | ICICI Prudential Mutual Fund
Debt Watch | ICICI Prudential Mutual Fundiciciprumf
6 views2 slides
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam... by
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...Amil baba
6 views1 slide

Recently uploaded(20)

Jeremy Hunt's letter to Nausicaa Delfas by Henry Tapper
Jeremy Hunt's letter to Nausicaa DelfasJeremy Hunt's letter to Nausicaa Delfas
Jeremy Hunt's letter to Nausicaa Delfas
Henry Tapper516 views
Debt Watch | ICICI Prudential Mutual Fund by iciciprumf
Debt Watch | ICICI Prudential Mutual FundDebt Watch | ICICI Prudential Mutual Fund
Debt Watch | ICICI Prudential Mutual Fund
iciciprumf6 views
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam... by Amil baba
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...
Pandit No2 Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam...
Amil baba6 views
The breath of the investment grade and the unpredictability of inflation - Eu... by Antonis Zairis
The breath of the investment grade and the unpredictability of inflation - Eu...The breath of the investment grade and the unpredictability of inflation - Eu...
The breath of the investment grade and the unpredictability of inflation - Eu...
Antonis Zairis7 views
Stock Market Brief Deck 121.pdf by Michael Silva
Stock Market Brief Deck 121.pdfStock Market Brief Deck 121.pdf
Stock Market Brief Deck 121.pdf
Michael Silva17 views
Teaching Third Generation Islamic Economics by Asad Zaman
Teaching Third Generation Islamic EconomicsTeaching Third Generation Islamic Economics
Teaching Third Generation Islamic Economics
Asad Zaman52 views
What is Credit Default Swaps by MksSkyView
What is Credit Default SwapsWhat is Credit Default Swaps
What is Credit Default Swaps
MksSkyView8 views
Indias Sparkling Future : Lab-Grown Diamonds in Focus by anujadeodhar4
Indias Sparkling Future : Lab-Grown Diamonds in FocusIndias Sparkling Future : Lab-Grown Diamonds in Focus
Indias Sparkling Future : Lab-Grown Diamonds in Focus
anujadeodhar47 views
1_updated_Axis India Manufacturing Fund-NFO One pager.pdf by multigainfinancial
1_updated_Axis India Manufacturing Fund-NFO One pager.pdf1_updated_Axis India Manufacturing Fund-NFO One pager.pdf
1_updated_Axis India Manufacturing Fund-NFO One pager.pdf
Embracing the eFarming Challenge.pdf by ramadhan04116
Embracing the eFarming Challenge.pdfEmbracing the eFarming Challenge.pdf
Embracing the eFarming Challenge.pdf
ramadhan041165 views
GroupPresentation_MicroEconomics by BethanyAline
GroupPresentation_MicroEconomicsGroupPresentation_MicroEconomics
GroupPresentation_MicroEconomics
BethanyAline33 views
Development Economics.pptx by Nithin Kumar
Development Economics.pptxDevelopment Economics.pptx
Development Economics.pptx
Nithin Kumar9 views

Pourquoi Ruby on Rails ça déchire ?