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

Repensando o Desenvolvimento Web com Ruby on Rails