SlideShare a Scribd company logo
1 of 35
Download to read offline
Ruby on Rails
Ruby on Rails
Pourquoi ça déchire ?
whoami



Simon COURTOIS
 CTO chez Selectra

  Githug: simonc
Twitter: @happynoff
MV C
M odel View C ontroller
OR M
Object R elational Mapping
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"
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
Conventions
Configuration
Active Record
articles

                                      # app/models/article.rb
id        title    body   author_id   class Article < ActiveRec...
                                        belongs_to :author
1         ...      ...    1           end

                                      # app/models/author.rb
                                      class Author < ActiveRec...
     authors
                                        has_many :articles
                                      end
     id     name
                                      article = Article.first
     1      John Doe
                                      article.author.name
                                      #=> “John Doe”
Active Record


MySQL
PostgreSQL
SQLite
...
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"


                                             action du contrôleur
             URL
                                contrôleur
        verbe HTTP
                         paramètre
Vues
# app/controller/hello_controller.rb
class HelloController < ApplicationController
  def index
    @name = params[:name]
  end
end


# app/views/hello/index.html.erb
Bonjour <%= @name %>




                    Conventions !
Helpers
# app/controller/articles_controller.rb
class ArticlesController < ApplicationController
  def new
    @article = Article.new
  end
end

 Title                 <%= form_for @article do |f| %>
                         <p><%= f.label :title, "Title" %><br />
                            <%= f.text_field :title %></p>

 Body                    <p><%= f.label :body, "Body" %><br />
                            <%= f.text_area :body %></p>

                         <p><%= f.submit %></p>
                       <% end %>
 Create Article
Railties

$ rake routes
GET /hello/:name   { :controller => "hello", :action => "index" }

$ rails server
Lance un serveur web sur http://localhost:3000/

$ rails console
Lance une console avec le contexte de l’application
  >> Article.first.title
  #=> "hello world"
Générateurs

$ rails generate model author name:string
  invoke active_record
      create db/migrate/20120108151543_create_authors.rb
      create app/models/author.rb



     instructions de création de la table authors


    modèle Author
Générateurs

$ rails g scaffold author name:string
create   db/migrate/20120108152723_create_authors.rb
create   app/models/author.rb                               modèle
route    resources :authors                  routes
create   app/controllers/authors_controller.rb
                                                       contrôleur
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                 vues
create   app/views/authors/_form.html.erb

create   public/stylesheets/scaffold.css

                                           CSS par défaut
Générateurs
 # 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   }
                 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) %>
Générateurs
Générateurs
Générateurs
Générateurs
Générateurs
Générateurs
Générateurs
Générateurs
Les petits plus d’ActiveSupport

1.kilobytes!   #=> 1024


3.days.ago!!   #=> Sat, 04 Feb 2012 17:45:42 CET +01:00


"héhé test".parameterize! #=> "hehe-test"


“article”.pluralize! ! ! #=> "articles"
                   !
Extensibilité
  Grâce aux Gems
Vues et formulaires
<%= 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 %>                             slim + simple_form


                             = simple_form_for @article do |f|
                                = f.input :title
                                = f.input :body
                                = f.submit
Et tant d’autres

Mongoid                Pagination
     MongoDB                        Kaminari


  Carierwave           Système d’administration

  Upload de fichiers            Active Admin
Qui utilise Rails ?

 Twitter
                                  Github
               Basecamp

Pages Jaunes US
                             Groupon

     Shopify

                  http://rubyonrails.org/applications
Ressources

rubyonrails.org                     Site officiel

tutorials.jumpstartlab.com/topics   Tutorial très complet

railsforzombies.org                 Tutorial interactif

railstutorial.org/book              Livre gratuit en ligne

#rubyonrails.fr                     Channel IRC français
Questions ?
Merci !

More Related Content

What's hot

Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 
Presentation.Key
Presentation.KeyPresentation.Key
Presentation.Key
guesta2b31d
 
I18n
I18nI18n
I18n
soon
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
RORLAB
 

What's hot (20)

AngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro FrameworkAngularJS with Slim PHP Micro Framework
AngularJS with Slim PHP Micro Framework
 
Introduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress DevelopersIntroduction to AngularJS For WordPress Developers
Introduction to AngularJS For WordPress Developers
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Using Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in RubyUsing Sinatra to Build REST APIs in Ruby
Using Sinatra to Build REST APIs in Ruby
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 
Presentation.Key
Presentation.KeyPresentation.Key
Presentation.Key
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 
Ruby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter BootstrapRuby on Rails + AngularJS + Twitter Bootstrap
Ruby on Rails + AngularJS + Twitter Bootstrap
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
SPA using Rails & Backbone
SPA using Rails & BackboneSPA using Rails & Backbone
SPA using Rails & Backbone
 
I18n
I18nI18n
I18n
 
Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009Rails 2.3 and Rack - NHRuby Feb 2009
Rails 2.3 and Rack - NHRuby Feb 2009
 
REST in AngularJS
REST in AngularJSREST in AngularJS
REST in AngularJS
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman OrtegaIntroduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
 
Python for AngularJS
Python for AngularJSPython for AngularJS
Python for AngularJS
 
Using Angular with Rails
Using Angular with RailsUsing Angular with Rails
Using Angular with Rails
 
Slim RedBeanPHP and Knockout
Slim RedBeanPHP and KnockoutSlim RedBeanPHP and Knockout
Slim RedBeanPHP and Knockout
 
Rails::Engine
Rails::EngineRails::Engine
Rails::Engine
 
Action Controller Overview, Season 2
Action Controller Overview, Season 2Action Controller Overview, Season 2
Action Controller Overview, Season 2
 
Curso rails
Curso railsCurso rails
Curso rails
 

Similar to Introduction à Ruby

Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 

Similar to Introduction à Ruby (20)

Pourquoi Ruby on Rails ça déchire ?
Pourquoi Ruby on Rails ça déchire ?Pourquoi Ruby on Rails ça déchire ?
Pourquoi Ruby on Rails ça déchire ?
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11Ruby on Rails at PROMPT ISEL '11
Ruby on Rails at PROMPT ISEL '11
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Cocoa on-rails-3rd
Cocoa on-rails-3rdCocoa on-rails-3rd
Cocoa on-rails-3rd
 
Supa fast Ruby + Rails
Supa fast Ruby + RailsSupa fast Ruby + Rails
Supa fast Ruby + Rails
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
 
Be happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP ItuBe happy with Ruby on Rails - CEUNSP Itu
Be happy with Ruby on Rails - CEUNSP Itu
 
Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Ruby on Rails introduction
Ruby on Rails introduction Ruby on Rails introduction
Ruby on Rails introduction
 
Trailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick Sutterer
 
Ruby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developerRuby on Rails survival guide of an aged Java developer
Ruby on Rails survival guide of an aged Java developer
 
Getting Started with Rails
Getting Started with RailsGetting Started with Rails
Getting Started with Rails
 
Rails Rookies Bootcamp - Blogger
Rails Rookies Bootcamp - BloggerRails Rookies Bootcamp - Blogger
Rails Rookies Bootcamp - Blogger
 

More from Microsoft

More from Microsoft (20)

Uwp + Xamarin : Du nouveau en terre du milieu
Uwp + Xamarin : Du nouveau en terre du milieuUwp + Xamarin : Du nouveau en terre du milieu
Uwp + Xamarin : Du nouveau en terre du milieu
 
La Blockchain pas à PaaS
La Blockchain pas à PaaSLa Blockchain pas à PaaS
La Blockchain pas à PaaS
 
Tester, Monitorer et Déployer son application mobile
Tester, Monitorer et Déployer son application mobileTester, Monitorer et Déployer son application mobile
Tester, Monitorer et Déployer son application mobile
 
Windows 10, un an après – Nouveautés & Démo
Windows 10, un an après – Nouveautés & Démo Windows 10, un an après – Nouveautés & Démo
Windows 10, un an après – Nouveautés & Démo
 
Prenez votre pied avec les bots et cognitive services.
Prenez votre pied avec les bots et cognitive services.Prenez votre pied avec les bots et cognitive services.
Prenez votre pied avec les bots et cognitive services.
 
Office 365 Dev PnP & PowerShell : exploitez enfin le potentiel de votre écosy...
Office 365 Dev PnP & PowerShell : exploitez enfin le potentiel de votre écosy...Office 365 Dev PnP & PowerShell : exploitez enfin le potentiel de votre écosy...
Office 365 Dev PnP & PowerShell : exploitez enfin le potentiel de votre écosy...
 
Créer un bot de A à Z
Créer un bot de A à ZCréer un bot de A à Z
Créer un bot de A à Z
 
Microsoft Composition, pierre angulaire de vos applications ?
Microsoft Composition, pierre angulaire de vos applications ?Microsoft Composition, pierre angulaire de vos applications ?
Microsoft Composition, pierre angulaire de vos applications ?
 
Les nouveautés SQL Server 2016
Les nouveautés SQL Server 2016Les nouveautés SQL Server 2016
Les nouveautés SQL Server 2016
 
Conteneurs Linux ou Windows : quelles approches pour des IT agiles ?
Conteneurs Linux ou Windows : quelles approches pour des IT agiles ?Conteneurs Linux ou Windows : quelles approches pour des IT agiles ?
Conteneurs Linux ou Windows : quelles approches pour des IT agiles ?
 
Administration et supervision depuis le Cloud avec Azure Logs Analytics
Administration et supervision depuis le Cloud avec Azure Logs AnalyticsAdministration et supervision depuis le Cloud avec Azure Logs Analytics
Administration et supervision depuis le Cloud avec Azure Logs Analytics
 
Retour d'expérience de projets Azure IoT "large scale" (MicroServices, portag...
Retour d'expérience de projets Azure IoT "large scale" (MicroServices, portag...Retour d'expérience de projets Azure IoT "large scale" (MicroServices, portag...
Retour d'expérience de projets Azure IoT "large scale" (MicroServices, portag...
 
Plan de Reprise d'Activité avec Azure Site Recovery
Plan de Reprise d'Activité avec Azure Site RecoveryPlan de Reprise d'Activité avec Azure Site Recovery
Plan de Reprise d'Activité avec Azure Site Recovery
 
Modélisation, déploiement et gestion des infrastructures Cloud : outils et bo...
Modélisation, déploiement et gestion des infrastructures Cloud : outils et bo...Modélisation, déploiement et gestion des infrastructures Cloud : outils et bo...
Modélisation, déploiement et gestion des infrastructures Cloud : outils et bo...
 
Transformation de la représentation : De la VR à la RA, aller & retour.
Transformation de la représentation : De la VR à la RA, aller & retour.Transformation de la représentation : De la VR à la RA, aller & retour.
Transformation de la représentation : De la VR à la RA, aller & retour.
 
Quelles architectures pour vos applications Cloud, de la VM au conteneur : ça...
Quelles architectures pour vos applications Cloud, de la VM au conteneur : ça...Quelles architectures pour vos applications Cloud, de la VM au conteneur : ça...
Quelles architectures pour vos applications Cloud, de la VM au conteneur : ça...
 
Introduction à ASP.NET Core
Introduction à ASP.NET CoreIntroduction à ASP.NET Core
Introduction à ASP.NET Core
 
Open Source et Microsoft Azure, rêve ou réalité ?
Open Source et Microsoft Azure, rêve ou réalité ?Open Source et Microsoft Azure, rêve ou réalité ?
Open Source et Microsoft Azure, rêve ou réalité ?
 
Comment développer sur la console Xbox One avec une application Universal Win...
Comment développer sur la console Xbox One avec une application Universal Win...Comment développer sur la console Xbox One avec une application Universal Win...
Comment développer sur la console Xbox One avec une application Universal Win...
 
Azure Service Fabric pour les développeurs
Azure Service Fabric pour les développeursAzure Service Fabric pour les développeurs
Azure Service Fabric pour les développeurs
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

Introduction à Ruby

  • 2. Ruby on Rails Pourquoi ça déchire ?
  • 3. whoami Simon COURTOIS CTO chez Selectra Githug: simonc Twitter: @happynoff
  • 5. M odel View C ontroller
  • 8. 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"
  • 9. 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
  • 11. Active Record articles # app/models/article.rb id title body author_id class Article < ActiveRec... belongs_to :author 1 ... ... 1 end # app/models/author.rb class Author < ActiveRec... authors has_many :articles end id name article = Article.first 1 John Doe article.author.name #=> “John Doe”
  • 13. 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" action du contrôleur URL contrôleur verbe HTTP paramètre
  • 14. Vues # app/controller/hello_controller.rb class HelloController < ApplicationController def index @name = params[:name] end end # app/views/hello/index.html.erb Bonjour <%= @name %> Conventions !
  • 15. Helpers # app/controller/articles_controller.rb class ArticlesController < ApplicationController def new @article = Article.new end end Title <%= form_for @article do |f| %> <p><%= f.label :title, "Title" %><br /> <%= f.text_field :title %></p> Body <p><%= f.label :body, "Body" %><br /> <%= f.text_area :body %></p> <p><%= f.submit %></p> <% end %> Create Article
  • 16. Railties $ rake routes GET /hello/:name { :controller => "hello", :action => "index" } $ rails server Lance un serveur web sur http://localhost:3000/ $ rails console Lance une console avec le contexte de l’application >> Article.first.title #=> "hello world"
  • 17. Générateurs $ rails generate model author name:string invoke active_record create db/migrate/20120108151543_create_authors.rb create app/models/author.rb instructions de création de la table authors modèle Author
  • 18. Générateurs $ rails g scaffold author name:string create db/migrate/20120108152723_create_authors.rb create app/models/author.rb modèle route resources :authors routes create app/controllers/authors_controller.rb contrôleur 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 vues create app/views/authors/_form.html.erb create public/stylesheets/scaffold.css CSS par défaut
  • 19. Générateurs # 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 } 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) %>
  • 28. Les petits plus d’ActiveSupport 1.kilobytes! #=> 1024 3.days.ago!! #=> Sat, 04 Feb 2012 17:45:42 CET +01:00 "héhé test".parameterize! #=> "hehe-test" “article”.pluralize! ! ! #=> "articles" !
  • 30. Vues et formulaires <%= 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 %> slim + simple_form = simple_form_for @article do |f| = f.input :title = f.input :body = f.submit
  • 31. Et tant d’autres Mongoid Pagination MongoDB Kaminari Carierwave Système d’administration Upload de fichiers Active Admin
  • 32. Qui utilise Rails ? Twitter Github Basecamp Pages Jaunes US Groupon Shopify http://rubyonrails.org/applications
  • 33. Ressources rubyonrails.org Site officiel tutorials.jumpstartlab.com/topics Tutorial très complet railsforzombies.org Tutorial interactif railstutorial.org/book Livre gratuit en ligne #rubyonrails.fr Channel IRC français