56
Initiation à Ruby on Rails @humancoders

Initiation à Ruby on Rails

Embed Size (px)

DESCRIPTION

Cette conférence a pour but de vous faire (re)découvrir le framework web Ruby on Rails. En une heure, nous vous montrerons comment développer une application simple et la déployer sur Microsoft Azure. Nous nous ferons découvrir le dynamisme de la communauté Ruby.

Citation preview

Page 1: Initiation à Ruby on Rails

Initiation à Ruby on Rails

@humancoders

Page 2: Initiation à Ruby on Rails

@matthieusegret

Page 3: Initiation à Ruby on Rails

Matthieu Segret

Formateur Ruby on Rails

Cofondateur de Human Coders

Page 4: Initiation à Ruby on Rails

Formation

Page 5: Initiation à Ruby on Rails

Un langage : Ruby

Page 6: Initiation à Ruby on Rails

•Langage interprété / orienté objet

•Libre - Licence Ruby et GPL

•Version 1.9.3 (bientôt 2.0)

•Apparu en 1995

Ruby

Page 7: Initiation à Ruby on Rails
Page 8: Initiation à Ruby on Rails
Page 9: Initiation à Ruby on Rails

puts "Hello world"

Ruby

"ruby is cool".length # 12

-42.abs # 42

"Nice Day Isn't It?".downcase.split # ["nice", "day", "isn't", "it?"]

Page 10: Initiation à Ruby on Rails

class Book def initialize(name) @name = name end

def name @name endend

Ruby

book = Book.new("Programming Ruby")

book.name # "Programming Ruby"

Page 11: Initiation à Ruby on Rails
Page 12: Initiation à Ruby on Rails
Page 13: Initiation à Ruby on Rails

Un framework : Ruby on Rails

Page 14: Initiation à Ruby on Rails

•Framework web écrit en Ruby

•Libre - MIT

•Version 3.2 (bientôt 4.0)

•Apparu en 2004

Ruby on Rails

Page 15: Initiation à Ruby on Rails

Convention over

Configuration

Page 16: Initiation à Ruby on Rails

DRY

(Don’t Repeat Yourself)

Page 17: Initiation à Ruby on Rails

Projet : MyNotes

Page 18: Initiation à Ruby on Rails

Projet : MyNotes

$ rails new MyNotes•Créer un nouveau projet

$ cd MyNotes

$ rails server•Démarrer le serveur

Page 19: Initiation à Ruby on Rails
Page 20: Initiation à Ruby on Rails

View

Controller

Model

Routing

Page 21: Initiation à Ruby on Rails
Page 22: Initiation à Ruby on Rails

CRUD

Page 23: Initiation à Ruby on Rails

Create

Read

Update

Delete

CRUD

Page 24: Initiation à Ruby on Rails

Ressource : notes

notes

id integer

title varchar

content text

Page 25: Initiation à Ruby on Rails

$ rails generate scaffold note title content:text

invoke active_recordcreate db/migrate/20130130171611_create_notes.rbcreate app/models/note.rbinvoke test_unitcreate test/unit/note_test.rbcreate test/fixtures/notes.ymlinvoke resource_routeroute resources :notesinvoke scaffold_controllercreate app/controllers/notes_controller.rbinvoke erbcreate app/views/notescreate app/views/notes/index.html.erbcreate app/views/notes/edit.html.erbcreate app/views/notes/show.html.erbcreate app/views/notes/new.html.erbcreate app/views/notes/_form.html.erb...

Génération du CRUD

Page 26: Initiation à Ruby on Rails

Migration

Page 27: Initiation à Ruby on Rails

migration 1

migration 2

migration 3

migration 4

devise_create_users

acts_as_follower

create_notes

add_profile_to_users20110720095338_

20110718190746_

20110715205012_

20110605152153_

rake db:migrate rake db:rollback

current

.rb

Migration

Page 28: Initiation à Ruby on Rails

Migration

class CreateNotes < ActiveRecord::Migration

def change create_table :notes do |t| t.string :title t.text :content

t.timestamps end end

end

db/migrate/20130130175117_create_notes.rb

$ rake db:migrate

Page 29: Initiation à Ruby on Rails

Base de données

notes

id integer

title varchar

content text

Page 30: Initiation à Ruby on Rails
Page 31: Initiation à Ruby on Rails

Modèle

Page 32: Initiation à Ruby on Rails

View

Controller

Model

Routing

Page 33: Initiation à Ruby on Rails

Modèle

class Note < ActiveRecord::Baseend

app/models/note.rb

Page 34: Initiation à Ruby on Rails

Modèle : création

Note.create(content: "I created Ruby", title: "Matz")

Page 35: Initiation à Ruby on Rails

Modèle : mise à jour

note = Note.find(1)note.content = "I love Ruby"note.save

Page 36: Initiation à Ruby on Rails

Modèle : lecture

Note.where(:title => "Matz").order("title ASC").limit(5)

Page 37: Initiation à Ruby on Rails

Modèle : suppression

Note.find(1).destroy

Page 38: Initiation à Ruby on Rails

Vue

Page 39: Initiation à Ruby on Rails

View

Controller

Model

Routing

Page 40: Initiation à Ruby on Rails

ERB

<p> <b>Title:</b> <%= @note.title %></p>

<p> <b>Content:</b> <%= @note.content %></p>

app/views/notes/show.html.erb

Page 41: Initiation à Ruby on Rails

Formulaires

<%= form_for(@note) do |f| %> <%= f.label :title %> <%= f.text_field :title %> <%= f.label :content %> <%= f.text_area :content %> <%= f.submit %><% end %>

Page 42: Initiation à Ruby on Rails

Contrôleur

Page 43: Initiation à Ruby on Rails

View

Controller

Model

Routing

Page 44: Initiation à Ruby on Rails

Contrôleur

class NotesController < ApplicationController def show @note = Note.find(params[:id]) endend

app/controllers/notes_controller.rb

app/views/notes/show.html.erb

Request

GET /notes/1

<p> <b>Title:</b> <%= @note.title %></p>

Page 45: Initiation à Ruby on Rails

Déploiement

Page 46: Initiation à Ruby on Rails
Page 47: Initiation à Ruby on Rails

Les gems

Page 48: Initiation à Ruby on Rails

Indexation

Twitter

NoSQLPaiement en ligne

Géolocalisation

ParsingPagination

Cache

Tâches de fonds

Upload de fichiers

FacebookAuthentification

LocalisationOAuth

A/B teste

LDAP

Page 49: Initiation à Ruby on Rails

La commautéeFrançaise

Page 50: Initiation à Ruby on Rails

Montpellier

Lyon

Toulouse

Nantes

Rennes

Lille

Paris

Sophia Antipolis

Strasbourg

Marseille

Compiegne

Bordeaux

Page 51: Initiation à Ruby on Rails

Aller plus loin

Page 52: Initiation à Ruby on Rails
Page 53: Initiation à Ruby on Rails

Programming Ruby 1.9 (3rd edition)

Agile Web Development with Rails (4th edition)

Page 54: Initiation à Ruby on Rails
Page 55: Initiation à Ruby on Rails

Formation

Page 56: Initiation à Ruby on Rails

@humancodersMerci !