pourquoi ruby et rails déchirent

Post on 16-May-2015

257 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Et bien il faut lire la présentation !

TRANSCRIPT

POURQUOI RUBY ET RAILS DÉCHIRENT !

Par Nicolas Ledez

RUBY 1/3

• Interprété

• Objet

• Multiparadigme

• Multiplateforme

• Libre, gratuit, etc

RUBY 2/3

• Ramasse-miettes

• Gestion d'exceptions

• Expressions rationnelles (Regexp)

• Blocs

• Extensions en C

RUBY 3/3

• Héritage simple

• Mixin -> « héritage multiple »

• Réflexion

• Crée en 1995

VIRTUAL MACHINE

• Matz's Ruby Interpreter – Cruby

• JRuby

• Rubinius

• MacRuby

• mruby

• RubyMotion

AUTOUR DU LANGAGE

POUR LES DEV

• Rspec, Cucumber, Minitest, ...

• HAML, SASS, Compass, ...

• Pow, Spork, Guard, ...

• Bundler, RVM, Rbenv, Pik, ...

• Rails, Sinatra, ...

• Vagrant

POUR LA PRODUCTION

• Unicorn, Passenger, ...

• Capistrano, Pupetts, Chef, ...

• Graylog2, God, ...

POUR LES DEV

• Cucumber

• Guard, SASS, Compass, ...

• Vagrant

• Graylog2, God, ...

ET ENCORE...

• + de 43 667 gems sur RubyGems.org

• ruby-toolbox.com

RAILS

Uglifier

Rackjson

i18nERB ActiveRecord

CMV

CM V!"#$ %#w !&'r!$$#r

MOR

MO Rb(#)' #$*'%!&*$ *pp%&+

ACTIVE RECORD

# app/models/article.rbclass Article < ActiveRecord::Baseend

article = Article.first

article.title#=> "hello world"

articlesarticlesarticlesid title body1 hello world This is a body

ACTIVE RECORDarticlesarticlesarticlesarticles

id title body published1 hello world This is a body 12 other art. Not published 0

articles = Article.where(published: 1)

articles.count#=> 1

CONFIGURATION

CONFIGURATIONC!&v#&'%!&,

ACTIVE RECORDarticlesarticlesarticlesarticles

id title body author_id1 ... ... 1

authorsauthorsid name1 John Doe

# app/models/article.rbclass Article < ActiveRec... belongs_to :authorend

# app/models/author.rbclass Author < ActiveRec... has_many :articlesend

article = Article.first

article.author.name#=> “John Doe”

ACTIVE RECORD

M-SQLP.'+r#SQLSQL%'#...

ROUTING

http://example.com/hello/John

# app/controller/hello_controller.rbclass HelloController < ApplicationController def index @name = params[:name] endend

# config/routes.rbget "hello/:name" => "hello#index"

URL

verbe HTTPcontrôleur

action du contrôleur

paramètre

VUES# app/controller/hello_controller.rbclass HelloController < ApplicationController def index @name = params[:name] endend

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

C!&v#&'%!&, !

HELPERS# app/controller/articles_controller.rbclass ArticlesController < ApplicationController def new @article = Article.new endend

<%= 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

RAILTIES$ rake routesGET /hello/:name { :controller => "hello", :action => "index" }

$ rails serverLance un serveur web sur http://localhost:3000/

$ rails consoleLance 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:stringcreate db/migrate/20120108152723_create_authors.rbcreate app/models/author.rb

route resources :authors

create app/controllers/authors_controller.rb

create app/views/authors/index.html.erbcreate app/views/authors/edit.html.erbcreate app/views/authors/show.html.erbcreate app/views/authors/new.html.erbcreate app/views/authors/_form.html.erb

create public/stylesheets/scaffold.css

modèleroutes

contrôleur

vues

CSS par défaut

GÉNÉRATEURS# config/routes.rbresources :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 %>

= simple_form_for @article do |f| = f.input :title = f.input :body = f.submit

slim + simple_form

ET TANT D’AUTRESM!"#!$%

K&'$"&r$

C&r$(rw&v(

A)*$v( A%'$"

MongoDB

Pagination

Upload de fichiers

Système d’administration

QUI UTILISE RAILS ?Tw$**(r

B&+()&'pG$*,-b

Gr!-p!"P&#(+ J&-"(+ US

S,!p$f.

http://rubyonrails.org/applications

J’INSTALLE TOUT ÇA COMMENT ?

JRUBY

LES RESSOURCES

UN GRAND MERCI

• A Simon Courtois

• @happynoff

• Pour ses slides :

• http://blog.happynoff.fr/post/pourquoi-ruby-on-rails-ca-dechire

top related