57
Ruby on Rails

Ruby On Rails

Embed Size (px)

DESCRIPTION

Apresentado em 24/03/2008

Citation preview

Page 1: Ruby On Rails

Ruby on Rails

Page 2: Ruby On Rails

O que é Ruby on Rails?

Page 3: Ruby On Rails

Ruby on Rails Linguagem + Framework

Page 4: Ruby On Rails
Page 5: Ruby On Rails

Um pouco de história

Tecnologia Japonesa

Criada por Yukihiro “Matz” Matsumoto

Foi lançada em 1995

Tem traços de várias outras linguagens

Open Source

Page 6: Ruby On Rails

Características do Ruby

Sintaxe Simples

Orientação a Objetos e Herança Simples

Classes abertas e Tipagem dinâmica

Metaprogramação e DSLs

Standard Library e RubyGems

Multiplataforma

Page 7: Ruby On Rails

Princípios do Ruby

Page 8: Ruby On Rails

"Você deve fazer códigos que resolvam seus problemas, e não os problemas da linguagem e/ou

interpretador/compilador"

Page 9: Ruby On Rails

Exemplo de código

Page 10: Ruby On Rails

5.times { print “Hello!” }

exit unless “restaurant”.include? “aura”

[‘toast’,‘cheese’,‘wine’].each { |food| print food.capitalize }

Page 11: Ruby On Rails

class Person

attr_reader :name #cria um getter para o atributo name

attr_accessor :hair #cria getter e setter

def initialize(name, hair)

@name, @hair = name, hair

end

def walk

“Walking”

end

end

Lennon = Person.new(“John”, “Dark”)

Lennon.class_eval do

def play_guitar

“playing”

end

end

Page 12: Ruby On Rails

receita "Bolo de Fubá" do

ingrediente "Farinha", "1 kilo" ingrediente "Açúcar", "200 gramas" ingrediente "Ovos", "2 unidades"

preparo "Misture todos ingrediantes" preparo "Leve ao forno" preparo "Sirva"

tempo "2 horas"

porcoes 3

end

Page 13: Ruby On Rails
Page 14: Ruby On Rails

Um pouco de História

Lançado em Julho/2004

Criado por David Heinemeier Hansson

Open Source

Foco para desenvolvimento Web

Atualmente está na versão 2.0

Page 15: Ruby On Rails

Características do Rails

Page 16: Ruby On Rails

(Meta)Framework

Page 17: Ruby On Rails

Metaframework

ActiveRecordActionPackActionMailerActiveSupportActiveResource

Page 18: Ruby On Rails

MVCModel-View-Controller

Page 19: Ruby On Rails
Page 20: Ruby On Rails
Page 21: Ruby On Rails

Extensível

Page 22: Ruby On Rails

Suporte a diversos Bancos de dadosMySQL, PostgreSQL, SQLite, Oracle, SQL Server, DB2

Page 23: Ruby On Rails

Agilidade

Page 24: Ruby On Rails
Page 25: Ruby On Rails

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

TopicoForm topicoForm = (TopicoForm)form; Topico topico = new Topico(); topico.setTitulo(topicoForm.getTitulo()); topico.setDescricao(topicoForm.getDescricao()); TopicoDAOMysql topicoDao = new TopicoDAOMysql(); try{ topicoDao.adiciona(topico); } catch(Exception e){ throw new Exception("Erro ao adicionar topico " +e); } ActionForward forward = mapping.findForward("Cadastrado"); return forward; } public void adiciona (Topico topico) throws Exception{ Connection conn = null; 64 ConexaoBD conBD = ConexaoBD.getInstancia(); conn = conBD.getConnection(); PreparedStatement pstmt = null; String sql = ""; int rowsAfected = 0;

try {

if (conn == null) throw new Exception("Conexão não foi estabelecida."); sql = "insert into Topicos (" + " titulo, descricao, data_postagem) " + " values((?), (?), now())"; pstmt = conn.prepareStatement(sql); pstmt.setString(1,topico.getTitulo()); pstmt.setString(2,topico.getDescricao()); rowsAfected = pstmt.executeUpdate(); if (rowsAfected <= 0) { throw new Exception("Erro na inserção do tópico. Por favor, tente novamente."); }

}catch(SQLException se) { throw new SQLException("Erro em TopicoDAOMysql.adiciona(): " + se.getMessage()); }catch (Exception e) { throw new Exception("Erro em TopicoDAOMysql.adiciona(): " + e.getMessage()); }finally { if(pstmt != null) pstmt.close(); conBD.returnConnection(conn); } }

Page 26: Ruby On Rails

def create @topico = Topico.new(params[:topico]) if @topico.save flash[:notice] = 'Topico criado com sucesso.' redirect_to :action => 'list' else render :action => 'new' end end

Page 27: Ruby On Rails

Extraído de uma necessidade realBasecamp da 37signals

Page 28: Ruby On Rails
Page 29: Ruby On Rails

FREE!

Page 30: Ruby On Rails

Princípios do Rails

Page 31: Ruby On Rails

DRY!Don't Repeat Yourself

Page 32: Ruby On Rails

CTRL + C / CRTL + V

Page 33: Ruby On Rails

Convention Over Configuration

Page 34: Ruby On Rails

Tradução de Convention Over Configuration

Para desenvolvedores: menos código

Para clientes: menos tempo

Para vendedores: mais lucro

Page 35: Ruby On Rails

Mais sobre Rails

Suporte nativo a Ajax

Integração com controladores de versão

Sistema de cache de páginas

Suporte a Test Driven Development

Page 36: Ruby On Rails

Para onde o Rails vai?

Page 37: Ruby On Rails

Livros – Pragmatic Programmers

Page 38: Ruby On Rails

Livros – O’Reilly

Page 39: Ruby On Rails

Livros em Português

Page 40: Ruby On Rails

Cursos

• Unisinos• TechOffice/POA• Target Trust/POA• E-Genial (EAD)• SENAC/SC• PUC/MG• Object Training/SP

Page 41: Ruby On Rails

Who’s on Rails?

Page 42: Ruby On Rails
Page 43: Ruby On Rails

Implementação do Ruby dentro da JVM

Compilação de código Ruby par a bytecode Java

Estável e em utilização

Promete ganhos de performance consideráveis

Page 44: Ruby On Rails
Page 45: Ruby On Rails
Page 46: Ruby On Rails
Page 47: Ruby On Rails
Page 48: Ruby On Rails

Ruby on Rails já instalado no Mac OS X Leopard

Page 49: Ruby On Rails
Page 50: Ruby On Rails
Page 51: Ruby On Rails

Sistema de Microblogging

100% feito em Rails

Diversas APIs, integração com SMS, Gtalk, etc...

11.000 hits por segundo

Page 52: Ruby On Rails

Indexador de blogs brasileiros

100% feito em Rails

Desenvolvido em 4 dias

Page 53: Ruby On Rails

Porque Ruby on Rails?

Page 54: Ruby On Rails

Grails – Java

CakePHP – PHP

Django – Python

Monorail - ASP.NET

Waves, Merb - Ruby

Page 55: Ruby On Rails
Page 56: Ruby On Rails
Page 57: Ruby On Rails

Show me the code!