initiation à ruby on rails
Post on 05-Dec-2014
326 Views
Preview:
DESCRIPTION
TRANSCRIPT
Initiation à Ruby on Rails
@humancoders
@matthieusegret
Matthieu Segret
Formateur Ruby on Rails
Cofondateur de Human Coders
Formation
Un langage : Ruby
•Langage interprété / orienté objet
•Libre - Licence Ruby et GPL
•Version 1.9.3 (bientôt 2.0)
•Apparu en 1995
Ruby
puts "Hello world"
Ruby
"ruby is cool".length # 12
-42.abs # 42
"Nice Day Isn't It?".downcase.split # ["nice", "day", "isn't", "it?"]
class Book def initialize(name) @name = name end
def name @name endend
Ruby
book = Book.new("Programming Ruby")
book.name # "Programming Ruby"
Un framework : Ruby on Rails
•Framework web écrit en Ruby
•Libre - MIT
•Version 3.2 (bientôt 4.0)
•Apparu en 2004
Ruby on Rails
Convention over
Configuration
DRY
(Don’t Repeat Yourself)
Projet : MyNotes
Projet : MyNotes
$ rails new MyNotes•Créer un nouveau projet
$ cd MyNotes
$ rails server•Démarrer le serveur
View
Controller
Model
Routing
CRUD
Create
Read
Update
Delete
CRUD
Ressource : notes
notes
id integer
title varchar
content text
$ 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
Migration
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
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
Base de données
notes
id integer
title varchar
content text
Modèle
View
Controller
Model
Routing
Modèle
class Note < ActiveRecord::Baseend
app/models/note.rb
Modèle : création
Note.create(content: "I created Ruby", title: "Matz")
Modèle : mise à jour
note = Note.find(1)note.content = "I love Ruby"note.save
Modèle : lecture
Note.where(:title => "Matz").order("title ASC").limit(5)
Modèle : suppression
Note.find(1).destroy
Vue
View
Controller
Model
Routing
ERB
<p> <b>Title:</b> <%= @note.title %></p>
<p> <b>Content:</b> <%= @note.content %></p>
app/views/notes/show.html.erb
Formulaires
<%= form_for(@note) do |f| %> <%= f.label :title %> <%= f.text_field :title %> <%= f.label :content %> <%= f.text_area :content %> <%= f.submit %><% end %>
Contrôleur
View
Controller
Model
Routing
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>
Déploiement
Les gems
Indexation
NoSQLPaiement en ligne
Géolocalisation
ParsingPagination
Cache
Tâches de fonds
Upload de fichiers
FacebookAuthentification
LocalisationOAuth
A/B teste
LDAP
La commautéeFrançaise
Montpellier
Lyon
Toulouse
Nantes
Rennes
Lille
Paris
Sophia Antipolis
Strasbourg
Marseille
Compiegne
Bordeaux
Aller plus loin
Programming Ruby 1.9 (3rd edition)
Agile Web Development with Rails (4th edition)
Formation
@humancodersMerci !
top related