SlideShare a Scribd company logo
Rails 3
José Valim
Trabalho na
Plataforma Tecnologia
Rails 3 - The Developers Conference - 21aug2010
Autor de diversos
projetos open source
Rails Core
Rails 3 - The Developers Conference - 21aug2010
Rails 3
Rails 3
OMG! Isso é incrível!
Mais rápido
Agnóstico
Modular
Mas vocês já ouviram
    sobre isso...
Como Rails 3 mudará o
modo que desenvolvemos
      aplicações?
#1
Bundler
“can't activate activesupport (= 2.3.4,
      runtime), already activated
activesupport-2.3.5 (Gem::Exception)”
#1
require “activesupport”
}
                                Rubygems
#1                             carregará a
require “activesupport”       última versão:
                                   2.3.5
}
                                 Rubygems
#1                              carregará a
require “activesupport”        última versão:
                                    2.3.5


#2
gem “activesupport”, “2.3.4”
Boom!
OMG! Isso NÃO é incrível!
# Gem le
source 'http://gemcutter.org'

gem 'rails', ' 3.0.0 '
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'ruby-debug'
Bundler resolve
dependências e faz um
“lock” do seu load path
Bundler resolve
dependências e faz um
“lock” do seu load path
Bundler resolve
dependências e faz um
“lock” do seu load path
}
#1
activesupport-2.2.2
activesupport-2.3.4       Filesystem
activesupport-2.3.5
}
#1
activesupport-2.2.2
activesupport-2.3.4                Filesystem
activesupport-2.3.5


                               }
#2
gem “activesupport”, “2.3.4”       Gemfile
}
#1
activesupport-2.2.2
activesupport-2.3.4                Filesystem
activesupport-2.3.5


                               }
#2
gem “activesupport”, “2.3.4”       Gemfile




                               }
#3
activesupport-2.3.4                $LOAD_PATH
Bundler garante que
todos no mesmo projeto
   usam as mesmas
     dependências
Gerenciamento de dependências
        OMG! Isso é incrível!
#2
respond_with
Rails 2.3
def index
  @users = User.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml { render :xml => @users }
  end
end
Rails 3

respond_to :html, :xml

def index
  @users = User.all
  respond_with(@users)
end
Rails 3

respond_to :html, :xml

def index
  @users = User.all       Formato de
  respond_with(@users)    navegação
end
Rails 3

respond_to :html, :xml

def index                 Formato
  @users = User.all        de API
  respond_with(@users)
end
Navegação   API

 GET


POST



 PUT


DELETE
Navegação   API

 GET


POST



 PUT


DELETE
Navegação   API

 GET


POST



 PUT


DELETE
def index
  @users = User.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml { render :xml => @users }
  end
end
Navegação       API

 GET     render template


POST



 PUT


DELETE
def index
  @users = User.all

  respond_to do |format|
    format.html # index.html.erb
    format.xml { render :xml => @users }
  end
end
Navegação              API
                                 render
 GET     render template
                           resources.to_format


POST



 PUT


DELETE
def create
  @user = User.new(params[:user])

  respond_to do |format|
    if @user.save
      format.html { redirect_to(@user, :notice => 'User was
successfully created.') }
      format.xml { render :xml => @user, :status
=> :created, :location => @user }
    else
      format.html { render :action => "new" }
      format.xml { render :xml => @user.errors, :status
=> :unprocessable_entity }
    end
  end
end
Navegação              API
                                          render
       GET        render template
                                    resources.to_format
        Success
POST
        Failure


       PUT


   DELETE
if @user.save
  format.html { redirect_to(@user, :notice => 'User
was successfully created.') }
  format.xml { render :xml => @user, :status
=> :created, :location => @user }
Navegação                 API
                                               render
       GET         render template
                                         resources.to_format
        Success   redirect_to resource
POST
        Failure


       PUT


   DELETE
if @user.save
  format.html { redirect_to(@user, :notice => 'User
was successfully created.') }
  format.xml { render :xml => @user, :status
=> :created, :location => @user }
Navegação                 API
                                                render
       GET         render template
                                         resources.to_format
                                                render
        Success   redirect_to resource
                                          resource.to_format
POST
        Failure


       PUT


   DELETE
else
  format.html { render :action => "new" }
  format.xml { render :xml =>
@user.errors, :status => :unprocessable_entity }
Navegação                   API
                                                render
       GET         render template
                                         resources.to_format
                                                render
        Success   redirect_to resource
                                          resource.to_format
POST
        Failure       render :new        render resource.errors


       PUT


   DELETE
Navegação                    API
                                                  render
       GET          render template
                                           resources.to_format
                                                  render
        Success   redirect_to resource
                                            resource.to_format
POST
        Failure       render :new          render resource.errors

        Success   redirect_to resource           head :ok
PUT
        Failure        render :edit        render resource.errors

   DELETE         redirect_to collection         head :ok
Três variáveis

     Verbo HTTP
  Estado do recurso
Formato da requisição
respond_with(@user)
respond_with(@user)

 ActionController::Responder
respond_with(@user)

 ActionController::Responder




                                 Navegação                 API

                                                          render
                 GET          render template
                                                    resources.to_format
                                                          render
                  Success    redirect_to resource
                                                    resource.to_format
          POST
                                                          render
                   Failure       render :new
                                                      resource.errors

                  Success    redirect_to resource        head :ok
          PUT
                                                          render
                   Failure       render :edit
                                                      resource.errors
                                 redirect_to
             DELETE                                      head :ok
                                  collection
respond_with(@user)

 ActionController::Responder

                                                tabela em código


                                 Navegação                 API

                                                          render
                 GET          render template
                                                    resources.to_format
                                                          render
                  Success    redirect_to resource
                                                    resource.to_format
          POST
                                                          render
                   Failure       render :new
                                                      resource.errors

                  Success    redirect_to resource        head :ok
          PUT
                                                          render
                   Failure       render :edit
                                                      resource.errors
                                 redirect_to
             DELETE                                      head :ok
                                  collection
def create
  @user = User.new(params[:user])

  respond_to do |format|
    if @user.save
      format.html { redirect_to(@user, :notice => 'User was
successfully created.') }
      format.xml { render :xml => @user, :status
=> :created, :location => @user }
    else
      format.html { render :action => "new" }
      format.xml { render :xml => @user.errors, :status
=> :unprocessable_entity }
    end
  end
end
def create
  @user = User.new(params[:user])
  flash[:user] = 'User was successfully created.' if @user.save
  respond_with(@user)
end
Navegação                    API
                                                  render
       GET          render template
                                           resources.to_format
                                                  render
        Success   redirect_to resource
                                            resource.to_format
POST
        Failure       render :new          render resource.errors

        Success   redirect_to resource           head :ok
PUT
        Failure        render :edit        render resource.errors

   DELETE         redirect_to collection         head :ok
Navegação                    API
                                                  render
       GET          render template
                                           resources.to_format
                                                  render
        Success   redirect_to resource
                                            resource.to_format
POST
        Failure       render :new          render resource.errors

        Success   redirect_to resource           head :ok
PUT
        Failure        render :edit        render resource.errors

   DELETE         redirect_to collection         head :ok
Navegação                    API
                                                render
       GET          render template
                                         resources.to_format
                                                render
        Success   redirect_to collection
                                          resource.to_format
POST
        Failure       render :new          render resource.errors

        Success   redirect_to collection         head :ok
PUT
        Failure        render :edit        render resource.errors

   DELETE         redirect_to collection         head :ok
Rails 2.3

a) Senta e chora
b) Mata o cliente
Rails 3

a) Senta e chora
b) Mata o cliente
c) Crie o seu responder
DRY
OMG! Isso é incrível!
#3
ARel
Rails 2.3


cars = Car.all(:conditions => { :color => 'black'})

expensive_cars = Car.all(:conditions => { :colour =>
'black'}, :order => 'cars.price DESC', :limit => 10)
Rails 3

cars = Car.where(:color => 'black')

expensive_cars = cars.
  order('cars.price DESC').limit(10)
Rails 3

# controller
@cars = Car.where(:color => 'black')

# view
<% cache do %>
  <% @cars.each do |car| %>
    <%= car.name %>
  <% end %>
<% end %>
Rails 3
                   Não acessa o
                  banco de dados
# controller
@cars = Car.where(:color => 'black')

# view
<% cache do %>
  <% @cars.each do |car| %>
    <%= car.name %>
  <% end %>
<% end %>
Rails 3
                   Não acessa o
                  banco de dados
# controller
@cars = Car.where(:color => 'black')
                       Acessa o
# view
                    banco de dados
<% cache do %>
  <% @cars.each do |car| %>
    <%= car.name %>
  <% end %>
<% end %>
Melhor e mais rápido!
    OMG! Isso é incrível!
#4
ActiveSupport::Noti cations
É o “Facebook news
feed” da sua aplicação
ActiveSupport::Notifications.
  instrument "active_record.sql" do
  # query the database adapter
end
ActiveSupport::Notifications.
  subscribe /active_record/ do |*args|
  # do something
end
Plugins e gems não
precisam hackear o
  código do Rails
Menos hacks, melhor
manutenção e ecossistema
      OMG! Isso é incrível!
#5
Nova API do ActionMailer
É como se fosse a API do
     controller...
class Notifier < ActionMailer::Base
  default :from => "system@example.com"

  def signup_notification(recipient)
    @account = recipient
    attachments['image.jpg'] = File.read("image.jpg")
    mail(:to => recipient.email) do |format|
      format.html
      format.text
    end
  end
end
#1
             Class level defaults
class Notifier < ActionMailer::Base
  default :from => "system@example.com"

  def signup_notification(recipient)
    @account = recipient
    attachments['image.jpg'] = File.read("image.jpg")
    mail(:to => recipient.email) do |format|
      format.html
      format.text
    end
  end
end
#2
           Variáveis de instância
class Notifier < ActionMailer::Base
  default :from => "system@example.com"

  def signup_notification(recipient)
    @account = recipient
    attachments['image.jpg'] = File.read("image.jpg")
    mail(:to => recipient.email) do |format|
      format.html
      format.text
    end
  end
end
#3
        Anexos são como cookies
class Notifier < ActionMailer::Base
  default :from => "system@example.com"

  def signup_notification(recipient)
    @account = recipient
    attachments['image.jpg'] = File.read("image.jpg")
    mail(:to => recipient.email) do |format|
      format.html
      format.text
    end
  end
end
#4
   mail funciona como respond_to
class Notifier < ActionMailer::Base
  default :from => "system@example.com"

  def signup_notification(recipient)
    @account = recipient
    attachments['image.jpg'] = File.read("image.jpg")
    mail(:to => recipient.email) do |format|
      format.html
      format.text
    end
  end
end
Simples e mais poderoso
      OMG! Isso é incrível!
#6
ActiveModel
Quase todas as
aplicações precisam de
um modelo que tenham
que se comportar como
     ActiveRecord
Formulário de Contato
class ContactForm
  include ActiveModel::Conversion
  extend ActiveModel::Naming
  extend ActiveModel::Translation
  include ActiveModel::Validations

  attr_accessor :name, :email, :message

  def deliver
    valid? && Notifier.contact(self).deliver
  end

  def persisted?
    false
  end
end
ActiveModel desempenha
  um papel essencial no
      agnosticismo
User.model_name
 user.persisted?
   user.valid?
   user.errors
   user.to_key
 user.to_param
Liberdade de escolha
    OMG! Isso é incrível!
#7
Rails::Generators
Scaffold é mais que uma
ferramenta de aprendizado
Agora ele adapta ao seu
       work ow
Rails 2.3

   script/generate
dm_rspec_scaffold User
Rails 2.3

   script/generate
dm_rspec_scaffold User
   OMG! Isso NÃO é incrível!
E se eu quisesse usar
Datamapper, Rspec e
        Haml?
Rails 3

config.generators do |g|
  g.orm :datamapper
  g.template_engine :haml
  g.test_framework :rspec, :views => false
  g.fixture_replacement :factory_girl,
                         :dir => "spec/factories"
end
Rails 3


rails g scaffold User
   OMG! Isso é incrível!
Vocês podem customizar
cada pedaço do scaffold
Rails 3

RAILS_ROOT/lib/templates/erb/scaffold/index.html.erb
RAILS_ROOT/lib/templates/erb/scaffold/show.html.erb
RAILS_ROOT/lib/templates/erb/scaffold/new.html.erb
RAILS_ROOT/lib/templates/erb/scaffold/edit.html.erb
O scaffold muda como a
  sua aplicação muda!
Customização!
 OMG! Isso é incrível!
?!
    @plataformatec
blog.plataformatec.com

More Related Content

PDF
2007 Fsoss Drupal Under The Hood
James Walker
 
KEY
Rails Routing and URL design
hiq5
 
KEY
Getting started with Rails (2), Season 2
RORLAB
 
PPTX
Using the Features API
cgmonroe
 
PDF
Curso rails
Icalia Labs
 
PDF
Javabeans .pdf
Rajkiran Mummadi
 
PDF
Os Haase
oscon2007
 
PDF
TYPO3 Flow 2.0 (International PHP Conference 2013)
Robert Lemke
 
2007 Fsoss Drupal Under The Hood
James Walker
 
Rails Routing and URL design
hiq5
 
Getting started with Rails (2), Season 2
RORLAB
 
Using the Features API
cgmonroe
 
Curso rails
Icalia Labs
 
Javabeans .pdf
Rajkiran Mummadi
 
Os Haase
oscon2007
 
TYPO3 Flow 2.0 (International PHP Conference 2013)
Robert Lemke
 

What's hot (19)

DOC
Sel study notes
Lalit Singh
 
PDF
13 java beans
snopteck
 
PDF
WebGUI Developers Workshop
Plain Black Corporation
 
PDF
JSP Syntax_1
brecke
 
PDF
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
PDF
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Arun Gupta
 
PDF
Rails 3 Beautiful Code
GreggPollack
 
PDF
Silex Cheat Sheet
Andréia Bohner
 
PPTX
Admin High Availability
rsnarayanan
 
PPTX
Unit iv
bhushan_adavi
 
PPTX
Building and managing java projects with maven part-III
princeirfancivil
 
PDF
Layouts and Rendering in Rails, Season 2
RORLAB
 
PDF
JavaServer Faces 2.0 - JavaOne India 2011
Arun Gupta
 
PPTX
Java beans
Rajkiran Mummadi
 
PPT
Beans presentation
manjusha ganesan
 
PPTX
Javabeans
vamsitricks
 
PPTX
Maven II
princeirfancivil
 
TXT
Jsp Notes
Rajiv Gupta
 
KEY
Drupal 7 as a rad tool
Cary Gordon
 
Sel study notes
Lalit Singh
 
13 java beans
snopteck
 
WebGUI Developers Workshop
Plain Black Corporation
 
JSP Syntax_1
brecke
 
13th Sep, Drupal 7 advanced training by TCS
DrupalMumbai
 
Servlets 3.0 - Asynchronous, Extensibility, Ease-of-use @ JavaOne Brazil 2010
Arun Gupta
 
Rails 3 Beautiful Code
GreggPollack
 
Silex Cheat Sheet
Andréia Bohner
 
Admin High Availability
rsnarayanan
 
Unit iv
bhushan_adavi
 
Building and managing java projects with maven part-III
princeirfancivil
 
Layouts and Rendering in Rails, Season 2
RORLAB
 
JavaServer Faces 2.0 - JavaOne India 2011
Arun Gupta
 
Java beans
Rajkiran Mummadi
 
Beans presentation
manjusha ganesan
 
Javabeans
vamsitricks
 
Jsp Notes
Rajiv Gupta
 
Drupal 7 as a rad tool
Cary Gordon
 
Ad

Viewers also liked (9)

PPT
Joy to the World Remix
drcan2
 
PDF
O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010
Plataformatec
 
PPTX
Slides of old cumbernauld
Douglas Logan
 
PDF
Rails Contributors
Xavier Noria
 
PDF
Rails 2.3, 3.0 and 3.1 - RubyConfBR - 26oct2010
Plataformatec
 
PDF
As reais razões do porque eu devo ser Ágil - Agile Tour São Paulo
Plataformatec
 
KEY
Código Saudável => Programador Feliz - Rs on Rails 2010
Plataformatec
 
PDF
Do your own hacking evening - RubyConf UR
Plataformatec
 
Joy to the World Remix
drcan2
 
O que há de novo no Rails 3 - Ruby on Rails no Mundo Real - 23may2010
Plataformatec
 
Slides of old cumbernauld
Douglas Logan
 
Rails Contributors
Xavier Noria
 
Rails 2.3, 3.0 and 3.1 - RubyConfBR - 26oct2010
Plataformatec
 
As reais razões do porque eu devo ser Ágil - Agile Tour São Paulo
Plataformatec
 
Código Saudável => Programador Feliz - Rs on Rails 2010
Plataformatec
 
Do your own hacking evening - RubyConf UR
Plataformatec
 
Ad

Similar to Rails 3 - The Developers Conference - 21aug2010 (20)

PDF
The Rails Way
Michał Orman
 
KEY
Ruby/Rails
rstankov
 
PDF
Rest And Rails
Kaushik Jha
 
PDF
Caldera Learn - LoopConf WP API + Angular FTW Workshop
CalderaLearn
 
PDF
Introduction à Ruby
Microsoft
 
PDF
Building RESTful applications using Spring MVC
IndicThreads
 
PDF
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
PDF
Rails2 Pr
xibbar
 
PDF
Rails 2.0 Presentation
Scott Chacon
 
PDF
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 
PDF
Ruby on Rails at PROMPT ISEL '11
Pedro Cunha
 
PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 
PDF
Pourquoi ruby et rails déchirent
Nicolas Ledez
 
PDF
Spring5 New Features
Jay Lee
 
KEY
Routing 1, Season 1
RORLAB
 
KEY
BEAR (Suday) design
Akihito Koriyama
 
KEY
More to RoC weibo
shaokun
 
PDF
Rails vs Web2py
jonromero
 
PDF
WordPress REST API hacking
Jeroen van Dijk
 
KEY
Supa fast Ruby + Rails
Jean-Baptiste Feldis
 
The Rails Way
Michał Orman
 
Ruby/Rails
rstankov
 
Rest And Rails
Kaushik Jha
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
CalderaLearn
 
Introduction à Ruby
Microsoft
 
Building RESTful applications using Spring MVC
IndicThreads
 
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
Rails2 Pr
xibbar
 
Rails 2.0 Presentation
Scott Chacon
 
Be happy with Ruby on Rails - CEUNSP Itu
Lucas Renan
 
Ruby on Rails at PROMPT ISEL '11
Pedro Cunha
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 
Pourquoi ruby et rails déchirent
Nicolas Ledez
 
Spring5 New Features
Jay Lee
 
Routing 1, Season 1
RORLAB
 
BEAR (Suday) design
Akihito Koriyama
 
More to RoC weibo
shaokun
 
Rails vs Web2py
jonromero
 
WordPress REST API hacking
Jeroen van Dijk
 
Supa fast Ruby + Rails
Jean-Baptiste Feldis
 

More from Plataformatec (11)

PDF
Product Owner - Simples como dizem? - Agile Tour 2011
Plataformatec
 
KEY
Writing your own programming language to understand Ruby better - Euruko 2011
Plataformatec
 
KEY
Railties - Ruby Masters Conf - 26Feb2011
Plataformatec
 
KEY
CRUDing Open Source - WhyDay - 19aug2010
Plataformatec
 
KEY
Rails 3 - RS on Rails - 21aug2010
Plataformatec
 
PDF
Project Rescue - Oxente Rails - 05aug2010
Plataformatec
 
PDF
The Plafatorma Way - Oxente Rails - 05aug2010
Plataformatec
 
KEY
DSL or NoDSL - Euruko - 29may2010
Plataformatec
 
KEY
Classificação de textos - Dev in Sampa - 28nov2009
Plataformatec
 
PDF
Devise - RSLA - 13oct2009
Plataformatec
 
PDF
Thor - RSLA - 13oct2009
Plataformatec
 
Product Owner - Simples como dizem? - Agile Tour 2011
Plataformatec
 
Writing your own programming language to understand Ruby better - Euruko 2011
Plataformatec
 
Railties - Ruby Masters Conf - 26Feb2011
Plataformatec
 
CRUDing Open Source - WhyDay - 19aug2010
Plataformatec
 
Rails 3 - RS on Rails - 21aug2010
Plataformatec
 
Project Rescue - Oxente Rails - 05aug2010
Plataformatec
 
The Plafatorma Way - Oxente Rails - 05aug2010
Plataformatec
 
DSL or NoDSL - Euruko - 29may2010
Plataformatec
 
Classificação de textos - Dev in Sampa - 28nov2009
Plataformatec
 
Devise - RSLA - 13oct2009
Plataformatec
 
Thor - RSLA - 13oct2009
Plataformatec
 

Recently uploaded (20)

PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
The Future of Artificial Intelligence (AI)
Mukul
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 

Rails 3 - The Developers Conference - 21aug2010

  • 9. Rails 3 OMG! Isso é incrível!
  • 13. Mas vocês já ouviram sobre isso...
  • 14. Como Rails 3 mudará o modo que desenvolvemos aplicações?
  • 16. “can't activate activesupport (= 2.3.4, runtime), already activated activesupport-2.3.5 (Gem::Exception)”
  • 18. } Rubygems #1 carregará a require “activesupport” última versão: 2.3.5
  • 19. } Rubygems #1 carregará a require “activesupport” última versão: 2.3.5 #2 gem “activesupport”, “2.3.4”
  • 20. Boom! OMG! Isso NÃO é incrível!
  • 21. # Gem le source 'http://gemcutter.org' gem 'rails', ' 3.0.0 ' gem 'sqlite3-ruby', :require => 'sqlite3' gem 'ruby-debug'
  • 22. Bundler resolve dependências e faz um “lock” do seu load path
  • 23. Bundler resolve dependências e faz um “lock” do seu load path
  • 24. Bundler resolve dependências e faz um “lock” do seu load path
  • 25. } #1 activesupport-2.2.2 activesupport-2.3.4 Filesystem activesupport-2.3.5
  • 26. } #1 activesupport-2.2.2 activesupport-2.3.4 Filesystem activesupport-2.3.5 } #2 gem “activesupport”, “2.3.4” Gemfile
  • 27. } #1 activesupport-2.2.2 activesupport-2.3.4 Filesystem activesupport-2.3.5 } #2 gem “activesupport”, “2.3.4” Gemfile } #3 activesupport-2.3.4 $LOAD_PATH
  • 28. Bundler garante que todos no mesmo projeto usam as mesmas dependências
  • 29. Gerenciamento de dependências OMG! Isso é incrível!
  • 31. Rails 2.3 def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end
  • 32. Rails 3 respond_to :html, :xml def index @users = User.all respond_with(@users) end
  • 33. Rails 3 respond_to :html, :xml def index @users = User.all Formato de respond_with(@users) navegação end
  • 34. Rails 3 respond_to :html, :xml def index Formato @users = User.all de API respond_with(@users) end
  • 35. Navegação API GET POST PUT DELETE
  • 36. Navegação API GET POST PUT DELETE
  • 37. Navegação API GET POST PUT DELETE
  • 38. def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end
  • 39. Navegação API GET render template POST PUT DELETE
  • 40. def index @users = User.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end
  • 41. Navegação API render GET render template resources.to_format POST PUT DELETE
  • 42. def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end
  • 43. Navegação API render GET render template resources.to_format Success POST Failure PUT DELETE
  • 44. if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user }
  • 45. Navegação API render GET render template resources.to_format Success redirect_to resource POST Failure PUT DELETE
  • 46. if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user }
  • 47. Navegação API render GET render template resources.to_format render Success redirect_to resource resource.to_format POST Failure PUT DELETE
  • 48. else format.html { render :action => "new" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
  • 49. Navegação API render GET render template resources.to_format render Success redirect_to resource resource.to_format POST Failure render :new render resource.errors PUT DELETE
  • 50. Navegação API render GET render template resources.to_format render Success redirect_to resource resource.to_format POST Failure render :new render resource.errors Success redirect_to resource head :ok PUT Failure render :edit render resource.errors DELETE redirect_to collection head :ok
  • 51. Três variáveis Verbo HTTP Estado do recurso Formato da requisição
  • 54. respond_with(@user) ActionController::Responder Navegação API render GET render template resources.to_format render Success redirect_to resource resource.to_format POST render Failure render :new resource.errors Success redirect_to resource head :ok PUT render Failure render :edit resource.errors redirect_to DELETE head :ok collection
  • 55. respond_with(@user) ActionController::Responder tabela em código Navegação API render GET render template resources.to_format render Success redirect_to resource resource.to_format POST render Failure render :new resource.errors Success redirect_to resource head :ok PUT render Failure render :edit resource.errors redirect_to DELETE head :ok collection
  • 56. def create @user = User.new(params[:user]) respond_to do |format| if @user.save format.html { redirect_to(@user, :notice => 'User was successfully created.') } format.xml { render :xml => @user, :status => :created, :location => @user } else format.html { render :action => "new" } format.xml { render :xml => @user.errors, :status => :unprocessable_entity } end end end
  • 57. def create @user = User.new(params[:user]) flash[:user] = 'User was successfully created.' if @user.save respond_with(@user) end
  • 58. Navegação API render GET render template resources.to_format render Success redirect_to resource resource.to_format POST Failure render :new render resource.errors Success redirect_to resource head :ok PUT Failure render :edit render resource.errors DELETE redirect_to collection head :ok
  • 59. Navegação API render GET render template resources.to_format render Success redirect_to resource resource.to_format POST Failure render :new render resource.errors Success redirect_to resource head :ok PUT Failure render :edit render resource.errors DELETE redirect_to collection head :ok
  • 60. Navegação API render GET render template resources.to_format render Success redirect_to collection resource.to_format POST Failure render :new render resource.errors Success redirect_to collection head :ok PUT Failure render :edit render resource.errors DELETE redirect_to collection head :ok
  • 61. Rails 2.3 a) Senta e chora b) Mata o cliente
  • 62. Rails 3 a) Senta e chora b) Mata o cliente c) Crie o seu responder
  • 63. DRY OMG! Isso é incrível!
  • 65. Rails 2.3 cars = Car.all(:conditions => { :color => 'black'}) expensive_cars = Car.all(:conditions => { :colour => 'black'}, :order => 'cars.price DESC', :limit => 10)
  • 66. Rails 3 cars = Car.where(:color => 'black') expensive_cars = cars. order('cars.price DESC').limit(10)
  • 67. Rails 3 # controller @cars = Car.where(:color => 'black') # view <% cache do %> <% @cars.each do |car| %> <%= car.name %> <% end %> <% end %>
  • 68. Rails 3 Não acessa o banco de dados # controller @cars = Car.where(:color => 'black') # view <% cache do %> <% @cars.each do |car| %> <%= car.name %> <% end %> <% end %>
  • 69. Rails 3 Não acessa o banco de dados # controller @cars = Car.where(:color => 'black') Acessa o # view banco de dados <% cache do %> <% @cars.each do |car| %> <%= car.name %> <% end %> <% end %>
  • 70. Melhor e mais rápido! OMG! Isso é incrível!
  • 72. É o “Facebook news feed” da sua aplicação
  • 73. ActiveSupport::Notifications. instrument "active_record.sql" do # query the database adapter end
  • 74. ActiveSupport::Notifications. subscribe /active_record/ do |*args| # do something end
  • 75. Plugins e gems não precisam hackear o código do Rails
  • 76. Menos hacks, melhor manutenção e ecossistema OMG! Isso é incrível!
  • 77. #5 Nova API do ActionMailer
  • 78. É como se fosse a API do controller...
  • 79. class Notifier < ActionMailer::Base default :from => "[email protected]" def signup_notification(recipient) @account = recipient attachments['image.jpg'] = File.read("image.jpg") mail(:to => recipient.email) do |format| format.html format.text end end end
  • 80. #1 Class level defaults class Notifier < ActionMailer::Base default :from => "[email protected]" def signup_notification(recipient) @account = recipient attachments['image.jpg'] = File.read("image.jpg") mail(:to => recipient.email) do |format| format.html format.text end end end
  • 81. #2 Variáveis de instância class Notifier < ActionMailer::Base default :from => "[email protected]" def signup_notification(recipient) @account = recipient attachments['image.jpg'] = File.read("image.jpg") mail(:to => recipient.email) do |format| format.html format.text end end end
  • 82. #3 Anexos são como cookies class Notifier < ActionMailer::Base default :from => "[email protected]" def signup_notification(recipient) @account = recipient attachments['image.jpg'] = File.read("image.jpg") mail(:to => recipient.email) do |format| format.html format.text end end end
  • 83. #4 mail funciona como respond_to class Notifier < ActionMailer::Base default :from => "[email protected]" def signup_notification(recipient) @account = recipient attachments['image.jpg'] = File.read("image.jpg") mail(:to => recipient.email) do |format| format.html format.text end end end
  • 84. Simples e mais poderoso OMG! Isso é incrível!
  • 86. Quase todas as aplicações precisam de um modelo que tenham que se comportar como ActiveRecord
  • 88. class ContactForm include ActiveModel::Conversion extend ActiveModel::Naming extend ActiveModel::Translation include ActiveModel::Validations attr_accessor :name, :email, :message def deliver valid? && Notifier.contact(self).deliver end def persisted? false end end
  • 89. ActiveModel desempenha um papel essencial no agnosticismo
  • 90. User.model_name user.persisted? user.valid? user.errors user.to_key user.to_param
  • 91. Liberdade de escolha OMG! Isso é incrível!
  • 93. Scaffold é mais que uma ferramenta de aprendizado
  • 94. Agora ele adapta ao seu work ow
  • 95. Rails 2.3 script/generate dm_rspec_scaffold User
  • 96. Rails 2.3 script/generate dm_rspec_scaffold User OMG! Isso NÃO é incrível!
  • 97. E se eu quisesse usar Datamapper, Rspec e Haml?
  • 98. Rails 3 config.generators do |g| g.orm :datamapper g.template_engine :haml g.test_framework :rspec, :views => false g.fixture_replacement :factory_girl, :dir => "spec/factories" end
  • 99. Rails 3 rails g scaffold User OMG! Isso é incrível!
  • 100. Vocês podem customizar cada pedaço do scaffold
  • 102. O scaffold muda como a sua aplicação muda!
  • 103. Customização! OMG! Isso é incrível!
  • 104. ?! @plataformatec blog.plataformatec.com