Ruby and Rails
Una revolución en el desarrollo web
Esteban Manchado Velázquez
<zoso@grupocpd.com>
Grupo CPD
Presentaciones
[any material that should appear in print but not on the slide]
Ruby
They are focusing on machines. But in fact we need to focus on humans, on
how humans care about doing programming or operating the application of the
machines. We are the masters. They are the slaves.
Ruby
- (Perl + Smalltalk) / 2
- Completamente orientado a objetos
- Duck typing
- Sintaxis «humana»
- Sangrado libre
- Se busca la belleza
Ruby
- Uso de mayúsculas y minúsculas
- Bloques
- Documentación empotrada
- Inmaduro
- Comunidad abierta
¿Python?
- Orientación a objetos
- Bloques
- Más funcional
- Más flexible/peligroso
- Encapsulación
Ejemplo
class SerVivo
attr_accessor :nombre
attr_reader :edad
def initialize(nombre, edad)
@nombre = nombre
@edad = edad
@persona = false
end
def saludar
puts "Hola, me llamo #{@nombre}."
end
def persona?; @persona end
def personizar!; @persona = true end
def edad=(nueva_edad) @edad = nueva_edad.to_i end
end
Rails
- MVC (Model-View-Controller)
- DRY (Don't Repeat Yourself)
- Productividad
- Programación metrosexual
Rails
I tend to view "truly flexible" by another term: "Make everything equally
hard"
Modelo
class Sugerencia < ActiveRecord::Base
end
Modelo
class Sugerencia < ActiveRecord::Base
validates_presence_of :descripcion
belongs_to :sugerente,
:foreign_key => 'cumplimentador',
:class_name => 'Entidad'
has_many :rebotes, :order => "fecha DESC"
has_many :envios_comite,:order => "fecha_envio",
:class_name => "EnvioComite"
has_many :premios, :order => "fecha_resolucion",
:class_name => "EnvioComite",
:conditions
=> "premio <> '' AND
premio IS NOT NULL"
def tipo
sugerente.forma_juridica == 'PM' ? EXTERNA :
INTERNA
end
end
Vista
<h1>Cierre - </h1>
<div style="margin-top: 2ex"></div>
<div class="panel">
<div class="aviso">
No se ha enviado todavía el acuse de recibo
</div>
<input type="button" class="boton" name="acuse"
value="Enviar ahora">
</div>
Controlador
class SugerenciasController < ApplicationController
def list
if tipo_usuario == :empleado
redirect_to :action => 'estado'
return
end
@sugerencias = Sugerencia.find(:all, :limit => 5,
:order => "fecha")
end
def show
@sugerencia = Sugerencia.find(@params[:id])
end
def new
@sugerencia = Sugerencia.new
end
end
Otras cosas de Rails
- Servidor web
- Consola
- Ajax
- Migraciones
- Baterías de pruebas
- Puntos de ruptura
- Servicios web
- Extensiones