SlideShare una empresa de Scribd logo
1 de 71
Descargar para leer sin conexión
Présentation
technico-commerciale
deRubyonRails
Yann Klis, juin 2013
Ruby
on
Rails
Ruby
on
Rails
interprété
> 1 + 1
=> 2
gestiondelamémoire
GarbageCollector
orientéobjetpur
> 1 + 1
=> 2
> 1.send(:+, 1)
=> 2
orientéobjetpur
> nil.nil ?
=> true
orientéobjetpur
> true.class
=> TrueClass
dynamique
> ary = []
=> []
> ary.class.class_eval {
attr_accessor :total_entries
}
=> nil
> ary.total_entries = 42
=> 42
> ary.total_entries
=> 42
class Printing
def method_missing(m, *args)
if (name = /^test_(.+)$/.match(m.id2name))
print name[1]
end
end
End
> printing = Printing.new
> printing.test_hello
=> "hello"
> printing.test_pipo
=> "pipo"
dynamique
blocklambda, fonction anonyme, etc.
> ["a","b","c"].each_with_index{|element,i|
puts i
}
0
1
2
blocklambda, fonction anonyme, etc.
> ["a", "b", "c"].map{|element|
element.upcase
}
=> ["A", "B", "C"]
lisibilité
> 5.times { print "Odelay!" }
> Exit unless "restaurant".include?("aura")
> ['toast', 'cheese', 'wine'].each{|food|
print food.capitalize
}
Ruby ?QuelRuby ?
1.8.7
1.9.3
2.0.0
Ruby ?QuelRuby ?
1.8.7 MRI
1.9.3 MRI
2.0.0 MRI
rbx 2.0.0
JRuby 1.7.4
rbenvrvm
# rbenv list
1.8.7-p358
1.9.3-p392
2.0.0-p0
* 2.0.0-p195 (set by /home/yannski/.rbenv/version)
rbenv
# rbenv install jruby-1.7.4
# rbenv local jruby-1.7.4
bundler&Gemfile
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'rails-i18n'
gem 'sass-rails', '~> 4.0.0'
gem 'haml-rails', '>= 4.0.0'
gem 'mongoid', github: 'mongoid/mongoid'
Ruby
on
Rails
Model
View
Controller
Model
View
Controller
Convention
over
Configuration
Convention
over
Configuration
environments
# ls -l config/environments/
development.rb
production.rb
test.rb
DRY
DRYDon't Repeat Yourself
ActiveRecord
M in MVC
class Product < ActiveRecord::Base
end
ActiveRecord / migrations
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.text :description
t.timestamps
end
end
end
db/migrate/20130626120509_create_products.rb
app/models/product.rb
ActiveRecord / migrations
mysql> show tables;
+---------------------------------+
| Tables_in_monapppli_development |
+---------------------------------+
| products |
| schema_migrations |
+---------------------------------+
2 rows in set (0.00 sec)
mysql> describe schema_migrations;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| version | varchar(255) | NO | PRI | NULL | |
+---------+--------------+------+-----+---------+-------+
1 row in set (0.00 sec)
mysql> select * from schema_migrations;
+----------------+
| version |
+----------------+
| 20130626120509 |
+----------------+
1 row in set (0.00 sec)
irb(main):001:0> product = Product.new
=> #<Product id: nil, name: nil, description: nil, created_at: nil, updated_at: nil>
irb(main):002:0> product.name = "Macbook"
=> "Macbook"
irb(main):003:0> product.save
(0.4ms) BEGIN
SQL (0.3ms) INSERT INTO `products` (`created_at`, `name`, `updated_at`) VALUES
('2013-06-26 12:08:17', 'Macbook', '2013-06-26 12:08:17')
(4.7ms) COMMIT
=> true
ActiveRecord / migrations
irb(main):004:0> Product.count
(0.5ms) SELECT COUNT(*) FROM `products`
=> 1
irb(main):005:0> Product.first
Product Load (0.5ms) SELECT `products`.* FROM `products` ORDER BY
`products`.`id` ASC LIMIT 1
=> #<Product id: 1, name: "Macbook", description: nil, created_at: "2013-06-26
12:08:17", updated_at: "2013-06-26 12:08:17">
irb(main):006:0> Product.where(name: "Macbook")
Product Load (0.8ms) SELECT `products`.* FROM `products` WHERE
`products`.`name` = 'Macbook'
=> #<ActiveRecord::Relation [#<Product id: 1, name: "Macbook", description: nil,
created_at: "2013-06-26 12:08:17", updated_at: "2013-06-26 12:08:17">]>
irb(main):008:0> Product.where(name: "Macbook").first
Product Load (0.7ms) SELECT `products`.* FROM `products` WHERE
`products`.`name` = 'Macbook' ORDER BY `products`.`id` ASC LIMIT 1
=> #<Product id: 1, name: "Macbook", description: nil, created_at: "2013-06-26
12:08:17", updated_at: "2013-06-26 12:08:17">
ActiveRecord / query
> Product.where(name: "Macbook")
Product Load (0.8ms) SELECT `products`.* FROM `products` WHERE
`products`.`name` = 'Macbook'
=> #<ActiveRecord::Relation [#<Product id: 1, name: "Macbook", description: nil,
created_at: "2013-06-26 12:08:17", updated_at: "2013-06-26 12:08:17">]>
> Product.where(name: "Macbook").to_a
Product Load (0.4ms) SELECT `products`.* FROM `products` WHERE
`products`.`name` = 'Macbook'
=> [#<Product id: 1, name: "Macbook", description: nil, created_at: "2013-06-26
12:08:17", updated_at: "2013-06-26 12:08:17">]
ActiveRecord / query
class Product
validates_presence_of :name
end
ActiveRecord / validations
class CreateProducts < ActiveRecord::Migration
def change
create_table :products do |t|
t.string :name
t.text :description
t.timestamps
end
end
end
db/migrate/20130626120509_create_products.rb
app/models/product.rb
> product = Product.new
=> #<Product id: nil, name: nil, description: nil, created_at: nil, updated_at: nil>
> product.save
(0.3ms) BEGIN
(0.2ms) ROLLBACK
=> false
> product.errors
=> #<ActiveModel::Errors:0x007f2f9fb1bec8 @base=#<Product id: nil, name: nil,
description: nil, created_at: nil, updated_at: nil>, @messages={:name=>["can't be
blank"]}>
ActiveRecord / validations
class Product
validates_presence_of :name
belongs_to :category
end
ActiveRecord / associations
app/models/product.rb
class Category
has_many :products
end
app/models/category.rb
class Product
before_validate :reformat
before_save :check_name
after_save :rebuild_category
after_destroy :destroy_category_if_empty
end
ActiveRecord / life cycle
app/models/product.rb
ActiveModelActiveModel::Model
ActiveModel::Callbacks
ActiveModel::Validations
ActiveModel::Dirty
ActiveModel::AttributeMethods
ActiveModel::Serialization
ActiveModel::Translation
Routing
Restful
asset
pipeline
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require bootstrap
//= require bootstrap-datepicker
//= require jquery_nested_form
//= require ckeditor/init
//= require_tree .
app/assets/javascripts/application.js
asset pipeline
*= require "custombootstrap"
*= require "fontawesome"
*= require "datepicker"
*= require_self
app/assets/stylesheets/application.css.scss
asset pipeline
ActiveSupport
> "Je suis à la gare".blank ?
=> false
ActiveSupport
> "".present?
=> false
ActiveSupport
> "Je suis à la gare".parameterize
=> "je-suis-a-la-gare"
ActiveSupport
> "John était allongé à la table d'un
café quand soudain le loup
apparu.".truncate(22)
=> "John était allongé …"
ActiveSupport
ActionView
products.html.erb
products.html.haml
movies.json.erb
movies.xml.builder
ActionView
Test
Tests unitaires des models, des controllers, des helpers
Tests fonctionnels (rspec, capybara, etc.)
railsconsole
> Product.where(name: "Macbook")
Product Load (0.8ms) SELECT `products`.* FROM `products` WHERE
`products`.`name` = 'Macbook'
=> #<ActiveRecord::Relation [#<Product id: 1, name: "Macbook", description: nil,
created_at: "2013-06-26 12:08:17", updated_at: "2013-06-26 12:08:17">]>
> Product.where(name: "Macbook").to_a
Product Load (0.4ms) SELECT `products`.* FROM `products` WHERE
`products`.`name` = 'Macbook'
=> [#<Product id: 1, name: "Macbook", description: nil, created_at: "2013-06-26
12:08:17", updated_at: "2013-06-26 12:08:17">]
ActiveRecord / query
railsserver
railsgenerate
debugger
i18n
CommunautéRuby
Unecertainementalité,certes...
rake
make en ruby
capistrano
déploiement
rubygems.org
repository centralisé des gems
devise
authentification
omniauth
omniauth-facebook, omniauth-twitter,
omniauth-dailymotion, omniauth-github, ...
paperclip
upload de fichiers, stockage, thumbnails, etc.
will_paginate
pagination
state_machine
machine à états...
airbrake
gestion des exceptions
resque
gestion des jobs asynchrones
(backend Redis)
ApprendreRails
http://railsforzombies.org/
http://guides.rubyonrails.org/
Formation (chez Novelys!)

Más contenido relacionado

La actualidad más candente

Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
Pavel Novitsky
 
Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
Ivan Chepurnyi
 
Building Web Service Clients with ActiveModel
Building Web Service Clients with ActiveModelBuilding Web Service Clients with ActiveModel
Building Web Service Clients with ActiveModel
pauldix
 

La actualidad más candente (18)

ALPHA Script - XML Model
ALPHA Script - XML ModelALPHA Script - XML Model
ALPHA Script - XML Model
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Deploying Straight to Production
Deploying Straight to ProductionDeploying Straight to Production
Deploying Straight to Production
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
 
The secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you aboutThe secret unit testing tools no one has ever told you about
The secret unit testing tools no one has ever told you about
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
 
HTML Form Part 1
HTML Form Part 1HTML Form Part 1
HTML Form Part 1
 
Java Script
Java ScriptJava Script
Java Script
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
 
Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
 
Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007Introduction to Active Record - Silicon Valley Ruby Conference 2007
Introduction to Active Record - Silicon Valley Ruby Conference 2007
 
Mastering Oracle ADF Bindings
Mastering Oracle ADF BindingsMastering Oracle ADF Bindings
Mastering Oracle ADF Bindings
 
Taming forms with React
Taming forms with ReactTaming forms with React
Taming forms with React
 
Building Web Service Clients with ActiveModel
Building Web Service Clients with ActiveModelBuilding Web Service Clients with ActiveModel
Building Web Service Clients with ActiveModel
 
AngularJS
AngularJSAngularJS
AngularJS
 
Pruebas unitarias con django
Pruebas unitarias con djangoPruebas unitarias con django
Pruebas unitarias con django
 
Educate 2017: Customizing Authoring: How our APIs let you create powerful sol...
Educate 2017: Customizing Authoring: How our APIs let you create powerful sol...Educate 2017: Customizing Authoring: How our APIs let you create powerful sol...
Educate 2017: Customizing Authoring: How our APIs let you create powerful sol...
 
Symfony World - Symfony components and design patterns
Symfony World - Symfony components and design patternsSymfony World - Symfony components and design patterns
Symfony World - Symfony components and design patterns
 

Similar a Presentation technico-commercial-ruby-on-rails

Ruby on Rails Security Updated (Rails 3) at RailsWayCon
Ruby on Rails Security Updated (Rails 3) at RailsWayConRuby on Rails Security Updated (Rails 3) at RailsWayCon
Ruby on Rails Security Updated (Rails 3) at RailsWayCon
heikowebers
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
New Relic
 
Resource and view
Resource and viewResource and view
Resource and view
Papp Laszlo
 
Active Record Inheritance in Rails
Active Record Inheritance in RailsActive Record Inheritance in Rails
Active Record Inheritance in Rails
Sandip Ransing
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republic
Kaing Menglieng
 

Similar a Presentation technico-commercial-ruby-on-rails (20)

Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007Introduction to Active Record at MySQL Conference 2007
Introduction to Active Record at MySQL Conference 2007
 
Ruby on Rails Security Updated (Rails 3) at RailsWayCon
Ruby on Rails Security Updated (Rails 3) at RailsWayConRuby on Rails Security Updated (Rails 3) at RailsWayCon
Ruby on Rails Security Updated (Rails 3) at RailsWayCon
 
Intro to-rails-webperf
Intro to-rails-webperfIntro to-rails-webperf
Intro to-rails-webperf
 
Resource and view
Resource and viewResource and view
Resource and view
 
Testing My Patience
Testing My PatienceTesting My Patience
Testing My Patience
 
Why ruby
Why rubyWhy ruby
Why ruby
 
Using Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDBUsing Perl Stored Procedures for MariaDB
Using Perl Stored Procedures for MariaDB
 
Active Record Inheritance in Rails
Active Record Inheritance in RailsActive Record Inheritance in Rails
Active Record Inheritance in Rails
 
The Rails Way
The Rails WayThe Rails Way
The Rails Way
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
AngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.jsAngularJS vs. Ember.js vs. Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Avoiding cursors with sql server 2005 tech republic
Avoiding cursors with sql server 2005   tech republicAvoiding cursors with sql server 2005   tech republic
Avoiding cursors with sql server 2005 tech republic
 
Practical Celery
Practical CeleryPractical Celery
Practical Celery
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
 
Solid angular
Solid angularSolid angular
Solid angular
 
Triggers and Stored Procedures
Triggers and Stored ProceduresTriggers and Stored Procedures
Triggers and Stored Procedures
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Presentation technico-commercial-ruby-on-rails