ruby on rails na unip

129
Ruby on Rails

Upload: fabio-akita

Post on 13-Jan-2015

922 views

Category:

Technology


1 download

DESCRIPTION

Adaptação da minha palestra na InfoQ e na Campus Party para o grupo .Net Architects que se encontra na Unip. http://www.dotnetarchitects.net/ Foi muito legal.

TRANSCRIPT

Page 1: Ruby on Rails na Unip

Ruby on Rails

Page 2: Ruby on Rails na Unip

AkitaOnRails.com

Page 3: Ruby on Rails na Unip

http://www.akitaonrails.com

Page 4: Ruby on Rails na Unip

http://www.locaweb.com.br/rails

Page 5: Ruby on Rails na Unip

1

Page 6: Ruby on Rails na Unip

Joel Spolsky

Page 7: Ruby on Rails na Unip
Page 8: Ruby on Rails na Unip

“Without understanding functional programming, you can't invent MapReduce, the algorithm that makes Google so

massively scalable.”

“The Perils of JavaSchools” - Joel Spolsky - 29/12/2005

http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html

Page 9: Ruby on Rails na Unip

“The terms Map and Reduce come from Lisp and functional programming...”

“The Perils of JavaSchools” - Joel Spolsky - 29/12/2005

http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html

Page 10: Ruby on Rails na Unip

“The very fact that Google invented MapReduce, and Microsoft didn't, says something about why Microsoft is

still playing catch up.”

“The Perils of JavaSchools” - Joel Spolsky - 29/12/2005

http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html

Page 11: Ruby on Rails na Unip

Codificadoresx

Desenvolvedores

Page 12: Ruby on Rails na Unip
Page 13: Ruby on Rails na Unip
Page 14: Ruby on Rails na Unip
Page 15: Ruby on Rails na Unip

“SOFT”WARE

Page 16: Ruby on Rails na Unip
Page 17: Ruby on Rails na Unip
Page 18: Ruby on Rails na Unip

AGILIDADE

Page 19: Ruby on Rails na Unip
Page 20: Ruby on Rails na Unip

Estamos “descobrindo” maneiras melhores de desenvolver software na prática e

ajudando outros a desenvolver.

Page 21: Ruby on Rails na Unip

Big Design Up Front

Page 22: Ruby on Rails na Unip

Big Design Up Front

Page 23: Ruby on Rails na Unip

Escopo Fechado

Page 24: Ruby on Rails na Unip

Escopo Fechado

Page 25: Ruby on Rails na Unip

Faseamento em Cascata

Page 26: Ruby on Rails na Unip

Faseamento em Cascata

Page 27: Ruby on Rails na Unip

“Change Request”

Page 28: Ruby on Rails na Unip

“Change Request”

Page 29: Ruby on Rails na Unip

Ceticismo

Page 30: Ruby on Rails na Unip
Page 31: Ruby on Rails na Unip

Winston W. Royce - 1970

Page 32: Ruby on Rails na Unip

“I believe in this concept, but the implementation described above is risky

and invites failure.”

Winston W. Royce - 1970

Page 33: Ruby on Rails na Unip

“I believe in this concept, but the implementation described above is risky

and invites failure.”

Winston W. Royce - 1970

Page 34: Ruby on Rails na Unip

“I believe in this concept, but the implementation described above is risky

and invites failure.”

Winston W. Royce - 1970

Page 35: Ruby on Rails na Unip

“Cargo Cult”

Page 36: Ruby on Rails na Unip
Page 37: Ruby on Rails na Unip

2

Page 38: Ruby on Rails na Unip

1993

“Matz”

http://www.ruby-lang.org

Page 39: Ruby on Rails na Unip

2001

“Prag Dave”

http://www.rubycentral.com/book/http://www.pragprog.com/titles/ruby3/programming-ruby-1-9

Page 40: Ruby on Rails na Unip

2004

“DHH”

http://www.rubyonrails.orghttp://www.loudthinking.com

Page 41: Ruby on Rails na Unip

http://rubyonrails.org/screencasts

Page 42: Ruby on Rails na Unip

http://rubyonrails.org/screencasts

Page 43: Ruby on Rails na Unip

“Tornar as coisas simples fáceis e as coisas

complexas possíveis”

Filosofia Ruby

Page 44: Ruby on Rails na Unip

http://www.levenez.com/lang/

Page 45: Ruby on Rails na Unip

Ruby on Rails

Page 46: Ruby on Rails na Unip

RUBY

http://guides.rails.info/

Page 47: Ruby on Rails na Unip

ActiveSupportRails

RUBY

http://guides.rails.info/

Page 48: Ruby on Rails na Unip

ActionPack

ActionController

ActionView

ActiveSupportRails

RUBY

http://guides.rails.info/

Page 49: Ruby on Rails na Unip

ActiveRecord

ActionPack

ActionController

ActionView

ActiveSupportRails

RUBY

http://guides.rails.info/

Page 50: Ruby on Rails na Unip

ActiveRecord

ActionPack

ActionMailer

ActionController

ActionView

ActiveSupportRails

RUBY

http://guides.rails.info/

Page 51: Ruby on Rails na Unip

ActiveRecord

ActionPack

ActiveResource

ActionMailer

ActionController

ActionView

ActiveSupportRails

ActionWebService

RUBY

http://guides.rails.info/

Page 52: Ruby on Rails na Unip
Page 53: Ruby on Rails na Unip
Page 54: Ruby on Rails na Unip
Page 55: Ruby on Rails na Unip
Page 56: Ruby on Rails na Unip
Page 57: Ruby on Rails na Unip
Page 58: Ruby on Rails na Unip
Page 59: Ruby on Rails na Unip

describe Product do include ProductSpecHelper

before(:each) do @product = Product.new end

it "should not be valid when empty" do @product.should_not be_valid end

it "should be valid when having correct information" do @product.attributes = valid_product_attributes @product.should be_valid endend

RSpec

Page 60: Ruby on Rails na Unip

describe Product do include ProductSpecHelper

before(:each) do @product = Product.new end

it "should not be valid when empty" do @product.should_not be_valid end

it "should be valid when having correct information" do @product.attributes = valid_product_attributes @product.should be_valid endend

RSpec

rake spec

Page 61: Ruby on Rails na Unip

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Page 62: Ruby on Rails na Unip

class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category

validates_presence_of :name validates_presence_of :master_price validates_presence_of :description

make_permalink :with => :name, :field => :permalinkend

Model

Product.find(1)

Page 63: Ruby on Rails na Unip

class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) .find_all_by_user_id(current_user.id) end

create.after { self.current_user = @user }

create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end

Controller

Page 64: Ruby on Rails na Unip

class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) .find_all_by_user_id(current_user.id) end

create.after { self.current_user = @user }

create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end

Controller

/users/1

Page 65: Ruby on Rails na Unip

<div id="product-listing"> <%= breadcrumbs(@taxon) %> <br/> <%= render :partial => "shared/products.html.erb", :locals => {:products => @products, :taxon => @taxon } %></div>

<% content_for :sidebar do %> <td id="shop-by-col" valign="top"> <%= render :partial => "shared/taxonomies" %> </td><% end %>

<%= render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty? %>

Views ERB

Page 66: Ruby on Rails na Unip

#product-listing =breadcrumbs(@taxon) %br =render :partial => "shared/products.html.erb", :locals => {:products => @products, :taxon => @taxon}

-content_for :sidebar do %td#shop-by-col(:valign => "top") =render :partial => "shared/taxonomies" =render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty?

Views HAML

Page 67: Ruby on Rails na Unip

ActionController::Routing::Routes.draw do |map| map.connect ':controller/service.wsdl', :action => 'wsdl'

map.resources :products, :member => {:change_image => :post} map.resources :addresses map.resources :orders, :has_many => [:line_items]

map.namespace :admin do |admin| admin.resources :users admin.resources :products endend

Rotas RESTFul

Page 68: Ruby on Rails na Unip

ActionController::Routing::Routes.draw do |map| map.connect ':controller/service.wsdl', :action => 'wsdl'

map.resources :products, :member => {:change_image => :post} map.resources :addresses map.resources :orders, :has_many => [:line_items]

map.namespace :admin do |admin| admin.resources :users admin.resources :products endend

Rotas RESTFul

GET /products/newGET /productsPOST /productsGET /products/1GET /products/1/editPUT /products/1DESTROY /products/1

Page 69: Ruby on Rails na Unip

class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end

def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations endend

Migrations

Page 70: Ruby on Rails na Unip

class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end

def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations endend

Migrations

rake db:migrate

Page 71: Ruby on Rails na Unip
Page 72: Ruby on Rails na Unip

“Beautiful Code”

Page 73: Ruby on Rails na Unip
Page 74: Ruby on Rails na Unip
Page 75: Ruby on Rails na Unip

http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programminghttp://weblog.jamisbuck.org/2008/11/29/recovering-from-enterprise-video-available

Page 76: Ruby on Rails na Unip

11 mil classes!

46 só de Collections!

http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programminghttp://weblog.jamisbuck.org/2008/11/29/recovering-from-enterprise-video-available

Page 77: Ruby on Rails na Unip

• Modules:

• Enumerable

• Comparable

• Classes:

• Array

• Hash

• Set

• Sorted Set

Page 78: Ruby on Rails na Unip

• Modules:

• Enumerable

• Comparable

• Classes:

• Array

• Hash

• Set

• Sorted Set

1.400classes

só 6 de Collections!

Page 79: Ruby on Rails na Unip

• Convention over Configuration

• Don’t Repeat Yourself

• You Ain’t Gonna Need It

• Automação

• Boas Práticas

• Código Bonito

• Ferramentas Simples

Page 80: Ruby on Rails na Unip

http://macromates.comhttp://www.apple.com/macbook

Page 81: Ruby on Rails na Unip

3

Page 82: Ruby on Rails na Unip

Mitos

http://www.loudthinking.com/posts/29-the-rails-myths

Page 83: Ruby on Rails na Unip

Rails não Escala

Page 84: Ruby on Rails na Unip

FUD: http://www.techcrunch.com/2008/05/22/twitter-at-scale-will-it-work/

Page 85: Ruby on Rails na Unip

To put things into perspective, though,

Friendster was written in Java to start, and switched to

PHP. Myspace was written in ColdFusion and transitioned

to ASP.NET.

When people run into problems scaling sites they

often think that the language is the problem, but I think it’s

rarely the case. Blaine Cook

http://www.akitaonrails.com/2008/6/17/chatting-with-blaine-cook-twitter

http://www.akitaonrails.com/2008/6/17/chatting-with-blaine-cook-twitter

Page 86: Ruby on Rails na Unip

“The New York Times used Ruby on Rails to pull together, analyze and display election results in near real time on one of its busiest Web

traffic days ever. ”

http://www.computerworld.com.au/article/268003/ruby_rails_rolls_into_enterprise?fp=16&fpid=1

http://www.computerworld.com/action/article.do?command=viewArticleBasic&articleId=9120778

Page 87: Ruby on Rails na Unip

“They serve up 23 million visitors a month. The conversion resulted in 20,000 lines of Ruby code instead of 125,000 lines of Java code, and most importantly eased

the difficulty they had in maintaining it. Once complete, and optimized their site is now faster than before. They also completed the rewrite in three months with

four developers.”

http://www.railsonwave.com/railsonwave/2008/6/4/yellowpages-com-migrates-to-rails

http://www.akitaonrails.com/2008/11/21/rails-podcast-brasil-qcon-special-john-straw-yellowpages-com-and-matt-aimonetti-merbhttp://www.rubyonrailsexamples.com/sites-on-rails/yellowpagescom-goes-ror/

Page 88: Ruby on Rails na Unip

http://www.techcrunch.com/2008/01/24/hulu-discusses-private-beta-suggests-public-launch-time-frame/

Page 89: Ruby on Rails na Unip

http://www.blogblogs.com.br

Page 90: Ruby on Rails na Unip

Mitos

Page 91: Ruby on Rails na Unip

Deployment de Rails é difícil

Page 92: Ruby on Rails na Unip
Page 93: Ruby on Rails na Unip

Apache + FastCGI

LightTPD + FastCGI

Litespeed + SAPI

Apache + Mongrel

Nginx + Mongrel

Nginx + Thin

Page 94: Ruby on Rails na Unip

Apache + FastCGI

LightTPD + FastCGI

Litespeed + SAPI

Apache + Mongrel

Nginx + Mongrel

Nginx + Thin

Page 95: Ruby on Rails na Unip

Apache + FastCGI

LightTPD + FastCGI

Litespeed + SAPI

Apache + Mongrel

Nginx + Mongrel

Nginx + Thin

Page 96: Ruby on Rails na Unip

Apache + FastCGI

LightTPD + FastCGI

Litespeed + SAPI

Apache + Mongrel

Nginx + Mongrel

Nginx + Thin

Page 97: Ruby on Rails na Unip

Apache + FastCGI

LightTPD + FastCGI

Litespeed + SAPI

Apache + Mongrel

Nginx + Mongrel

Nginx + Thin

Page 98: Ruby on Rails na Unip

Apache + FastCGI

LightTPD + FastCGI

Litespeed + SAPI

Apache + Mongrel

Nginx + Mongrel

Nginx + Thin

Page 99: Ruby on Rails na Unip

http://phusion.nlhttp://www.modrails.com/

Page 100: Ruby on Rails na Unip

gem install passengerpassenger-install-apache2-module

http://phusion.nlhttp://www.modrails.com/

Page 101: Ruby on Rails na Unip
Page 102: Ruby on Rails na Unip
Page 103: Ruby on Rails na Unip

Mitos

Page 104: Ruby on Rails na Unip

Rails é mal documentado

Page 105: Ruby on Rails na Unip

Geoffrey

http://www.peepcode.com

Page 106: Ruby on Rails na Unip

Jason e Gregg

http://railsenvy.comhttp://envycasts.com

Page 107: Ruby on Rails na Unip

Ryan Bates

http://railscasts.com

Page 108: Ruby on Rails na Unip

Pratik Naik

http://guides.rails.info/

Page 109: Ruby on Rails na Unip

Satish Talim

http://rubylearning.org

Page 110: Ruby on Rails na Unip

Peter Cooper

http://rubyinside.comhttp://railsinside.comhttp://rubyflow.comhttp://jrubyinside.comhttp://yorails.com

Page 111: Ruby on Rails na Unip

_why

http://whytheluckystiff.net/

Page 112: Ruby on Rails na Unip

http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&field-keywords=ruby+rails&x=0&y=0

Page 113: Ruby on Rails na Unip
Page 114: Ruby on Rails na Unip

4

Page 115: Ruby on Rails na Unip

Open Source

Page 116: Ruby on Rails na Unip

Chris Wanstrath

http://github.com

Page 117: Ruby on Rails na Unip

http://rubyforge.orghttp://gitorious.org

Page 118: Ruby on Rails na Unip

http://jruby.codehaus.orghttp://www.macruby.orghttp://www.ironruby.nethttp://ruby.gemstone.com/http://rubini.us/

Page 119: Ruby on Rails na Unip

http://gettingreal.37signals.com/GR_por.phphttp://aprendaaprogramar.rubyonrails.pro.br/http://why.nomedojogo.com/http://rubyonrails.pro.brhttp://rubyonbr.org

Page 120: Ruby on Rails na Unip

http://gettingreal.37signals.com/GR_por.phphttp://aprendaaprogramar.rubyonrails.pro.br/http://why.nomedojogo.com/http://rubyonrails.pro.brhttp://rubyonbr.org

Page 121: Ruby on Rails na Unip

Conferências

Page 122: Ruby on Rails na Unip

http://www.confreaks.com/http://www.akitaonrails.com/railsconf2008

Page 123: Ruby on Rails na Unip

http://www.locaweb.com.br/railssummithttp://www.akitaonrails.com/railssummit2008

Page 124: Ruby on Rails na Unip
Page 125: Ruby on Rails na Unip
Page 126: Ruby on Rails na Unip
Page 127: Ruby on Rails na Unip
Page 128: Ruby on Rails na Unip

Especialista de uma coisa só é um amador em todo o

resto.

Page 129: Ruby on Rails na Unip

Obrigado!www.akitaonrails.com