Dans cette session vous apprendrez tout sur Ruby. Le langage, les frameworks, la communauté, mais surtout un esprit. Passé le teaser, Nicolas Ledez vous présentera comment Ruby peut vous apporter tous les jours une méthodologie dans votre travail, et des outils pour réaliser un prototype rapidement. Quel que soit votre langage d'origine, Ruby complète parfaitement votre boite à outils de développeur/administrateur système.
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
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
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