Successfully reported this slideshow.
Your SlideShare is downloading. ×

Pourquoi Ruby on Rails ça déchire ?

Ad

Simon Courtois - @happynoff
www.tinci.fr
Ruby on Rails
Why does it rock?

Ad

www.tinci.fr
Web
Development
Software
Development
X_
Consulting &
Support
@tincihq

Ad

www.tinci.fr
M V C

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Upcoming SlideShare
Introduction à Ruby
Introduction à Ruby
Loading in …3
×

Check these out next

1 of 35 Ad
1 of 35 Ad
Advertisement

More Related Content

Advertisement
Advertisement

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!

×