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 < Act...
www.tinci.fr
Active Record
articles
id title body published
1 hello world This is a body 1
2 other art. Not published 0
ar...
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...
www.tinci.fr
Active Record
MySQL
PostgreSQL
SQLite
…
www.tinci.fr
Routing
# app/controller/hello_controller.rb
class HelloController < ApplicationController
def index
@name = ...
www.tinci.fr
Views
# app/controller/hello_controller.rb
class HelloController < ApplicationController
def index
@name = pa...
www.tinci.fr
Helpers
# app/views/articles/index.html.erb
<%= @articles.each do |article| %>
<p><%= link_to article.title, ...
www.tinci.fr
Helpers
# app/controller/articles_controller.rb
class ArticlesController < ApplicationController
def new
@art...
www.tinci.fr
Railties
$ rake routes
GET /hello/:name { :controller => "hello", :action => "index" }
$ rails server
Starts ...
www.tinci.fr
Generators
$ rails generate model author name:string
invoke active_record	

create db/migrate/20120108151543_...
www.tinci.fr
Generators
$ rails g scaffold author name:string
create db/migrate/20120108152723_create_authors.rb	

create ...
www.tinci.fr
Generators
# config/routes.rb
resources :authors
authors
 
 GET
 
 /authors

 
 
 { action: index controller: ...
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:...
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 :titl...
www.tinci.fr
And many more
Mongoid
Kaminari
Carrierwave
Active Admin
MongoDB
Pagination
File upload
Administration interfa...
www.tinci.fr
Who is using Rails?
Twitter
Basecamp
Github
Groupon
US Yellow Pages
Shopify
http://rubyonrails.org/applicatio...
www.tinci.fr
Resources
rubyonrails.org Official website
tutorials.jumpstartlab.com/topics Very complete tutorial
railsforz...
www.tinci.fr
Questions?
www.tinci.fr
Thanks!
Upcoming SlideShare
Loading in …5
×

Pourquoi Ruby on Rails ça déchire ?

6,445 views

Published on

Présentation accompagnant mon talk du Meetup Paris.rb du 10 janvier 2012.

Published in: Economy & Finance, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
6,445
On SlideShare
0
From Embeds
0
Number of Embeds
3,098
Actions
Shares
0
Downloads
32
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Pourquoi Ruby on Rails ça déchire ?

  1. 1. Simon Courtois - @happynoff www.tinci.fr Ruby on Rails Why does it rock?
  2. 2. www.tinci.fr Web Development Software Development X_ Consulting & Support @tincihq
  3. 3. www.tinci.fr M V C
  4. 4. www.tinci.fr Model View Controller
  5. 5. www.tinci.fr O R M
  6. 6. www.tinci.fr Object Relational Mapping
  7. 7. 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"
  8. 8. 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
  9. 9. www.tinci.fr Conventions Configuration
  10. 10. 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”
  11. 11. www.tinci.fr Active Record MySQL PostgreSQL SQLite …
  12. 12. 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
  13. 13. 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 !
  14. 14. 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>
  15. 15. 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
  16. 16. 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"
  17. 17. 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
  18. 18. 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
  19. 19. 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) %>
  20. 20. www.tinci.fr Generators
  21. 21. www.tinci.fr Generators
  22. 22. www.tinci.fr Generators
  23. 23. www.tinci.fr Generators
  24. 24. www.tinci.fr Generators
  25. 25. www.tinci.fr Generators
  26. 26. www.tinci.fr Generators
  27. 27. www.tinci.fr Generators
  28. 28. 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"
  29. 29. www.tinci.fr Extensibility Thanks to gems
  30. 30. 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
  31. 31. www.tinci.fr And many more Mongoid Kaminari Carrierwave Active Admin MongoDB Pagination File upload Administration interface
  32. 32. www.tinci.fr Who is using Rails? Twitter Basecamp Github Groupon US Yellow Pages Shopify http://rubyonrails.org/applications
  33. 33. 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
  34. 34. www.tinci.fr Questions?
  35. 35. www.tinci.fr Thanks!

×