SlideShare a Scribd company logo
1 of 114
Repensando o Desenvolvimento Web com
 Ruby on Rails
Rails
Comunidade
Filosofia
DanteRegis.com
     @danteregis

Admin de Redes - TJ/SE
DanteRegis.com
                         @danteregis

                    Admin de Redes - TJ/SE




http://slideshare.net/danteregis
Você não vai aprender
  Ruby on Rails aqui
framework
David Heinemeier Hansson
                   2004
37signals
1400+
 desenvolvedores
jul/2004         0.5
     dez/2005          1.0
     mar/2006          1.1
     jan/2007          1.2
     dez/2007          2.0
     jun/2008          2.1
     nov/2008          2.2
     mar/2009          2.3
algum dia (em 2009?)   3.0
Empregos
(fonte: indeed.com)
MVC
opiniated
eXtreme Programming
TDD
REST
modularização
DRY
Convention
   over
Configuration
KISS
script/console
Model
Model
Model
Model
     id: integer

    name: string

     price: float

category_id: integer

   stock: integer

created_at: datetime

updated_at: datetime
Model
     id: integer

    name: string
                       x = Product.new
     price: float

category_id: integer

   stock: integer

created_at: datetime

updated_at: datetime
Model
     id: integer

    name: string
                       x = Product.new
     price: float       x.name = "Pão Jacó"
category_id: integer

   stock: integer

created_at: datetime

updated_at: datetime
Model
     id: integer

    name: string
                       x = Product.new
     price: float       x.name = "Pão Jacó"
category_id: integer   x.stock = "100
   stock: integer

created_at: datetime

updated_at: datetime
Model
     id: integer

    name: string
                       x = Product.new
     price: float       x.name = "Pão Jacó"
category_id: integer   x.stock = "100
   stock: integer      x.price = 0.15
created_at: datetime

updated_at: datetime
Model
     id: integer

    name: string
                       x = Product.new
     price: float       x.name = "Pão Jacó"
category_id: integer   x.stock = "100
   stock: integer      x.price = 0.15
created_at: datetime   x.save
updated_at: datetime
Model
Model



INSERT INTO `products` COLUMNS (`name`, `price`,
`stock`) VALUES ("Pão Jaco", 0.15, 100);
Model
Model

Product.first
Model

Product.first

Product.find_all_by_category_id(10)
Model

Product.first

Product.find_all_by_category_id(10)

Product.find_or_create_by_name("Margarina")
Model

Product.first

Product.find_all_by_category_id(10)

Product.find_or_create_by_name("Margarina")

Product.count
Model

Product.first

Product.find_all_by_category_id(10)

Product.find_or_create_by_name("Margarina")

Product.count

Product.average('price')
validations
associations
instance methods
Model



class Product < ActiveRecord::Base

end
Model
class Product < ActiveRecord::Base




end
Model
class Product < ActiveRecord::Base
  belongs_to :category




end
Model
class Product < ActiveRecord::Base
  belongs_to :category
  validates_presence_of :name




end
Model
class Product < ActiveRecord::Base
  belongs_to :category
  validates_presence_of :name
  validates_numericality_of :stock




end
Model
class Product < ActiveRecord::Base
  belongs_to :category
  validates_presence_of :name
  validates_numericality_of :stock


  def consume!
    stock -= 1
    save
  end


end
p = Product.new(:stock => "xxxxx")
p = Product.new(:stock => "xxxxx")
p.save
p = Product.new(:stock => "xxxxx")
p.save
#=> false
p = Product.first
p.category
p.category.name = "Mudei o nome"
p.category.save
has_many
class Category < ActiveRecord::Base
  has_many :products
end
cat.products
cat.products.new
cat.products.first
named scope
class Product < ActiveRecord::Base
  named_scope :low_stock, :conditions => ['stock <= 10']
end
Product.low_stock
#=> [.....]
Product.low_stock
#=> [.....]

category.products.low_stock
#=> [...]
SQL?
migrations
controle de versão
do banco de dados!
sem SQL!
class AddQuantityToCartProduct < ActiveRecord::Migration
class AddQuantityToCartProduct < ActiveRecord::Migration
  def self.up
    add_column :cart_products, :quantity, :integer
  end
class AddQuantityToCartProduct < ActiveRecord::Migration
  def self.up
    add_column :cart_products, :quantity, :integer
  end

  def self.down
    drop_column :cart_products, :quantity
  end
end
com SQL!
> 90%
 experiência pessoal
ActionController
session
render
filters
class ApplicationController < ActionController::Base
  before_filter :check_login

  def check_login
    render :text => "acesso negado!"
  end
end
flash
flash[:notice] = "Você logou no sistema"
cookies
respond_to
ActionView
erb
haml
erb
form_tag
form_for
<div>
  <span><%= flash[:notice] %></span>
</div>
<div>
  <% form_tag do %>
       <p>
         Usuário: <%= text_field_tag 'username' %>
       </p>
       <p>
         Senha: <%= password_field_tag 'password' %>
       </p>
       <p>
         <%= submit_tag 'Entrar' %>
       </p>
  <% end %>
</div>
Tempo para falar mal
de certas “soluções”
Fim do tempo para
falar mal de certas
     “soluções”
Comunidade
RailsConf
http://railsconf.com
Rails Summit Latin
      America
  http://railssummit.com.br
13 e 14 de outubro
      São Paulo/SP
Aldo França
Great Blogs ‘n People
Akita on Rails
 http://akitaonrails.com
Carlos Brando
 http://nomedojogo.com
Ozéias Sant’ana
   http://railsbox.org
Bruno Miranda
 http://brunomiranda.com
Ruby Onda
http://rubyonda.com
Nando Vieira
http://simplesideias.com.br
PeepCode
http://peepcode.com
RailsCasts
http://railscasts.com
http://slideshare.net/danteregis
dante@danteregis.com

More Related Content

What's hot

Two scoopsofdjango common patterns for forms
Two scoopsofdjango   common patterns for formsTwo scoopsofdjango   common patterns for forms
Two scoopsofdjango common patterns for forms
Shih-yi Wei
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
Jay Shirley
 
Web осень 2012 лекция 6
Web осень 2012 лекция 6Web осень 2012 лекция 6
Web осень 2012 лекция 6
Technopark
 
Web весна 2013 лекция 6
Web весна 2013 лекция 6Web весна 2013 лекция 6
Web весна 2013 лекция 6
Technopark
 
Top 5 Magento Secure Coding Best Practices
Top 5 Magento Secure Coding Best PracticesTop 5 Magento Secure Coding Best Practices
Top 5 Magento Secure Coding Best Practices
Oleksandr Zarichnyi
 
Presentation of the new OpenERP API. Raphael Collet, OpenERP
Presentation of the new OpenERP API. Raphael Collet, OpenERPPresentation of the new OpenERP API. Raphael Collet, OpenERP
Presentation of the new OpenERP API. Raphael Collet, OpenERP
Odoo
 

What's hot (18)

Optimization in django orm
Optimization in django ormOptimization in django orm
Optimization in django orm
 
Django tricks (2)
Django tricks (2)Django tricks (2)
Django tricks (2)
 
Two scoopsofdjango common patterns for forms
Two scoopsofdjango   common patterns for formsTwo scoopsofdjango   common patterns for forms
Two scoopsofdjango common patterns for forms
 
Scala on Your Phone
Scala on Your PhoneScala on Your Phone
Scala on Your Phone
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
PHPunit and you
PHPunit and youPHPunit and you
PHPunit and you
 
Desenvolvendo APIs usando Rails - Guru SC 2012
Desenvolvendo APIs usando Rails - Guru SC 2012Desenvolvendo APIs usando Rails - Guru SC 2012
Desenvolvendo APIs usando Rails - Guru SC 2012
 
Web осень 2012 лекция 6
Web осень 2012 лекция 6Web осень 2012 лекция 6
Web осень 2012 лекция 6
 
Web весна 2013 лекция 6
Web весна 2013 лекция 6Web весна 2013 лекция 6
Web весна 2013 лекция 6
 
Django ORM - Marcin Markiewicz
Django ORM - Marcin Markiewicz Django ORM - Marcin Markiewicz
Django ORM - Marcin Markiewicz
 
PHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the testsPHPUnit Episode iv.iii: Return of the tests
PHPUnit Episode iv.iii: Return of the tests
 
Two scoopsofdjango ch16 dealing with the user model
Two scoopsofdjango ch16   dealing with the user modelTwo scoopsofdjango ch16   dealing with the user model
Two scoopsofdjango ch16 dealing with the user model
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
 
Android HttpClient - new slide!
Android HttpClient - new slide!Android HttpClient - new slide!
Android HttpClient - new slide!
 
Top 5 Magento Secure Coding Best Practices
Top 5 Magento Secure Coding Best PracticesTop 5 Magento Secure Coding Best Practices
Top 5 Magento Secure Coding Best Practices
 
Javascript And J Query
Javascript And J QueryJavascript And J Query
Javascript And J Query
 
Presentation of the new OpenERP API. Raphael Collet, OpenERP
Presentation of the new OpenERP API. Raphael Collet, OpenERPPresentation of the new OpenERP API. Raphael Collet, OpenERP
Presentation of the new OpenERP API. Raphael Collet, OpenERP
 
Chainable datasource
Chainable datasourceChainable datasource
Chainable datasource
 

Viewers also liked

home depot Annual Report 1984
home depot Annual Report 1984home depot Annual Report 1984
home depot Annual Report 1984
finance2
 
valero energy Quarterly and Other SEC Reports 2008 1st
valero energy  Quarterly and Other  SEC Reports  2008  1stvalero energy  Quarterly and Other  SEC Reports  2008  1st
valero energy Quarterly and Other SEC Reports 2008 1st
finance2
 
Fiscal 2005 10-K Annual Report
Fiscal 2005 10-K Annual Report Fiscal 2005 10-K Annual Report
Fiscal 2005 10-K Annual Report
finance2
 

Viewers also liked (20)

home depot Annual Report 1984
home depot Annual Report 1984home depot Annual Report 1984
home depot Annual Report 1984
 
Taller de ecg (1)
Taller de ecg (1)Taller de ecg (1)
Taller de ecg (1)
 
Tackling a lack of local OER: How international OER adoption enhanced the qua...
Tackling a lack of local OER: How international OER adoption enhanced the qua...Tackling a lack of local OER: How international OER adoption enhanced the qua...
Tackling a lack of local OER: How international OER adoption enhanced the qua...
 
سلامة
سلامةسلامة
سلامة
 
Presentacion will goingto
Presentacion will goingto Presentacion will goingto
Presentacion will goingto
 
Final proyect
Final proyectFinal proyect
Final proyect
 
Snow universe (1)
Snow universe (1)Snow universe (1)
Snow universe (1)
 
SharePoint Saturday - Hybrid O365 BI Solution
SharePoint Saturday - Hybrid O365 BI SolutionSharePoint Saturday - Hybrid O365 BI Solution
SharePoint Saturday - Hybrid O365 BI Solution
 
current cv 2015
current cv 2015current cv 2015
current cv 2015
 
Aprendizaje autonomo
Aprendizaje autonomoAprendizaje autonomo
Aprendizaje autonomo
 
Objetivo 1 epistemologia
Objetivo 1 epistemologiaObjetivo 1 epistemologia
Objetivo 1 epistemologia
 
Afijos Ingles Instrumental
Afijos Ingles InstrumentalAfijos Ingles Instrumental
Afijos Ingles Instrumental
 
Traget audience profile sheet
Traget audience profile sheetTraget audience profile sheet
Traget audience profile sheet
 
Infografia epistemologia
Infografia epistemologiaInfografia epistemologia
Infografia epistemologia
 
The Evolution of UX Challenges
The Evolution of UX ChallengesThe Evolution of UX Challenges
The Evolution of UX Challenges
 
Paradigma de investigacion sociocritica
Paradigma de investigacion sociocriticaParadigma de investigacion sociocritica
Paradigma de investigacion sociocritica
 
Zookeeper
ZookeeperZookeeper
Zookeeper
 
Estructuras sociales
Estructuras socialesEstructuras sociales
Estructuras sociales
 
valero energy Quarterly and Other SEC Reports 2008 1st
valero energy  Quarterly and Other  SEC Reports  2008  1stvalero energy  Quarterly and Other  SEC Reports  2008  1st
valero energy Quarterly and Other SEC Reports 2008 1st
 
Fiscal 2005 10-K Annual Report
Fiscal 2005 10-K Annual Report Fiscal 2005 10-K Annual Report
Fiscal 2005 10-K Annual Report
 

Similar to Repensando o Desenvolvimento Web com Ruby on Rails

Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
Chris Alfano
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
Ciklum Ukraine
 
Active Record Inheritance in Rails
Active Record Inheritance in RailsActive Record Inheritance in Rails
Active Record Inheritance in Rails
Sandip Ransing
 

Similar to Repensando o Desenvolvimento Web com Ruby on Rails (20)

The Ring programming language version 1.3 book - Part 30 of 88
The Ring programming language version 1.3 book - Part 30 of 88The Ring programming language version 1.3 book - Part 30 of 88
The Ring programming language version 1.3 book - Part 30 of 88
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
MongoDB World 2018: Keynote
MongoDB World 2018: KeynoteMongoDB World 2018: Keynote
MongoDB World 2018: Keynote
 
The Boy Scout Rule
The Boy Scout RuleThe Boy Scout Rule
The Boy Scout Rule
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
How to optimize background processes - when Sylius meets Blackfire
How to optimize background processes - when Sylius meets BlackfireHow to optimize background processes - when Sylius meets Blackfire
How to optimize background processes - when Sylius meets Blackfire
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
Uniface Lectures Webinar - Building Responsive Applications with Uniface: Dev...
 
The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210The Ring programming language version 1.9 book - Part 54 of 210
The Ring programming language version 1.9 book - Part 54 of 210
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
 
Dart for Java Developers
Dart for Java DevelopersDart for Java Developers
Dart for Java Developers
 
Тестирование и Django
Тестирование и DjangoТестирование и Django
Тестирование и Django
 
Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQuery
 
The Role of Python in SPAs (Single-Page Applications)
The Role of Python in SPAs (Single-Page Applications)The Role of Python in SPAs (Single-Page Applications)
The Role of Python in SPAs (Single-Page Applications)
 
Unit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnitUnit testing PHP apps with PHPUnit
Unit testing PHP apps with PHPUnit
 
CiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForceCiklumJavaSat_15112011:Alex Kruk VMForce
CiklumJavaSat_15112011:Alex Kruk VMForce
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
React Native - Workshop
React Native - WorkshopReact Native - Workshop
React Native - Workshop
 
Active Record Inheritance in Rails
Active Record Inheritance in RailsActive Record Inheritance in Rails
Active Record Inheritance in Rails
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 

Repensando o Desenvolvimento Web com Ruby on Rails