3. FREVO ON RAILS
Rails 2 + Merb
Anunciado em dezembro de 2008
4. FREVO ON RAILS
Versão 3.0.0.beta1
Versão 3.0.0.beta2
Versão 3.0.0.beta3
Versão 3.0.0.beta4
Funciona em Ruby 1.8.7 e 1.9.2
Versão 3.0.0.rc1
re . N en .
e- ss ldr es
ris le hi ec
rp or r c pi
y. t
ad o
te 3 fo all
en age od sm
of t g ins
a
No nt
o
Co
34. FREVO ON RAILS
class PostsController < ApplicationController
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @posts }
end
end
def show
@post = Post.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @post }
end
end
...
end
35. FREVO ON RAILS
class PostsController < ApplicationController
respond_to :html, :xml, :json
def index
@posts = Post.all
respond_with(@posts)
end
def show
@post = Post.find(params[:id])
respond_with(@post)
end
...
end
58. FREVO ON RAILS
class Person
include ActiveModel::Validations
validates_presence_of :first_name, :last_name
attr_accessor :first_name, :last_name
end
59. FREVO ON RAILS
person = Person.new
person.valid? # false
person.errors # {:first_name=>["can't be bl...
p.first_name = 'John'
p.last_name = 'Travolta'
p.valid? # true
60. FREVO ON RAILS
Make Any Ruby Object Feel Like AR
http://yehudakatz.com/2010/01/10/activemodel-make-any-
ruby-object-feel-like-activerecord/
64. FREVO ON RAILS
module ActiveModel
module Validations
class CepValidator < EachValidator
FORMATO_CEP = /d{5}-d{3}/
def initialize(options)
super(options)
end
def validate_each(record, attribute, value)
unless valid?(value)
record.errors[attribute] = 'não é válido'
end
end
def valid?(value)
FORMATO_CEP =~ value
end
end
end
end
65. FREVO ON RAILS
require "#{Rails.root}/lib/validadores/cep_validator"
class Person < ActiveRecord::Base
validates :cep, cep: true
end
70. FREVO ON RAILS
class UserMailer < ActionMailer::Base
! def welcome(user)
! ! recipients user.email
! ! from “email@example.com”
! ! subject “Welcome to my site”
! ! body { :user => user }
! end
end
71. FREVO ON RAILS
class UserMailer < ActionMailer::Base
! default from: “email@example.com”
! def welcome(user)
! ! @user = user
! ! mail(to: user.email,
! ! ! subject: “Welcome to my site”)
! end
end