• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
O que vem por aí com Rails 3
 

O que vem por aí com Rails 3

on

  • 1,874 views

2º encontro de Frevo on Rails

2º encontro de Frevo on Rails

Statistics

Views

Total Views
1,874
Views on SlideShare
1,874
Embed Views
0

Actions

Likes
0
Downloads
17
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    O que vem por aí com Rails 3 O que vem por aí com Rails 3 Presentation Transcript

    • FREVO ON RAILS GRUPO DE USUÁRIOS RUBY/RAILS DE PERNAMBUCO RUBY ON RAILS 3 O que vem de novo por aí... GUILHERME CARVALHO E LAILSON BANDEIRA
    • FREVO ON RAILS “No, no another Rails upgrade!”
    • FREVO ON RAILS Rails 2 + Merb Anunciado em dezembro de 2008
    • 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
    • FREVO ON RAILS MAJOR UPGRADE
    • FREVO ON RAILS Mudanças arquiteturais importantes
    • FREVO ON RAILS RAILS
    • FREVO ON RAILS ACTIVE SUPPORT ACTIVE ACTION RECORD PACK RAILTIES ACTIVE ACTIVE MODEL RESOURCE ACTION MAILER
    • FREVO ON RAILS COMMAND INTERFACE
    • FREVO ON RAILS rails nome_da_app
    • FREVO ON RAILS rails new nome_da_app
    • FREVO ON RAILS script/server
    • FREVO ON RAILS rails server
    • FREVO ON RAILS rails s
    • FREVO ON RAILS script/generate controller nome_do_controlador
    • FREVO ON RAILS rails generate controller nome_do_controlador
    • FREVO ON RAILS rails g controller nome_do_controlador
    • FREVO ON RAILS console runner profiler dbconsole destroy plugin benchmarker
    • FREVO ON RAILS Gerenciamento de gems com o Bundler
    • FREVO ON RAILS ROUTING
    • FREVO ON RAILS Não se usa mais o map!
    • FREVO ON RAILS ActionController::Routing::Routes.draw do |map| map.resources :posts end
    • FREVO ON RAILS ActionController::Routing::Routes.draw do |map| resources :posts end
    • FREVO ON RAILS Resources e singular resources não mudaram
    • FREVO ON RAILS Namespaces e scopes
    • FREVO ON RAILS map.with_options(:namespace => “admin”) do |a| a.resources :photos end
    • FREVO ON RAILS namespace “admin” do resources :photos end
    • FREVO ON RAILS Scopes foram criados para auxiliar na organização
    • FREVO ON RAILS map.resources :photos, :member => {:preview => :get }
    • FREVO ON RAILS resources :photos do get :preview, on: :member end
    • FREVO ON RAILS Sai o método connect, entra o match
    • FREVO ON RAILS rake routes
    • FREVO ON RAILS RESPONDERS
    • 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
    • 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
    • FREVO ON RAILS É possível também criar outros responders
    • FREVO ON RAILS Three reasons to love Responders http://weblog.rubyonrails.org/2009/8/31/three-reasons-love-responder
    • FREVO ON RAILS ACTION CONTROLLER
    • FREVO ON RAILS Gargalo de performance: roteamento + renderização
    • FREVO ON RAILS Separação de responsabilidades: Action Dispatch
    • FREVO ON RAILS Hierarquia de controladores
    • FREVO ON RAILS AbstractController::Base ActionController::Metal ActionController::Base
    • FREVO ON RAILS ACTIVE RECORD QUERY API
    • FREVO ON RAILS Nova API de consulta Active Relation
    • FREVO ON RAILS @posts = Post.find(:all, ! :conditions => ['created_at > ?', date])
    • FREVO ON RAILS @posts = Post.where(['created_at > ?', date])
    • FREVO ON RAILS Lazy loading
    • FREVO ON RAILS @posts = Post.where(['created_at > ?', date]) if only_published? ! @posts = @posts.where(:published => true) end
    • FREVO ON RAILS # @posts.all @posts.each do |p| ! ... end
    • FREVO ON RAILS group from joins order where having includes limit select offset
    • FREVO ON RAILS minimum maximum first all sum last count average calculate
    • FREVO ON RAILS Active Record Query Interface 3 http://m.onkey.org/2010/1/22/active-record-query-interface
    • FREVO ON RAILS Escopos também foram simplificados
    • FREVO ON RAILS class Post < ActiveRecord::Base named_scope :published, :conditions => {:published => true} named_scope :unpublished, :conditions => {:published => false} end
    • FREVO ON RAILS class Post < ActiveRecord::Base scope :published, where(:published => true) scope :unpublished, where(:published => false) end
    • FREVO ON RAILS VALIDAÇÕES SEM MODELOS
    • FREVO ON RAILS Consequência da modularização Active Model
    • FREVO ON RAILS class Person include ActiveModel::Validations validates_presence_of :first_name, :last_name attr_accessor :first_name, :last_name end
    • 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
    • FREVO ON RAILS Make Any Ruby Object Feel Like AR http://yehudakatz.com/2010/01/10/activemodel-make-any- ruby-object-feel-like-activerecord/
    • FREVO ON RAILS VALIDADORES CUSTOMIZADOS
    • FREVO ON RAILS Agora é possível criar validadores que podem ser reusados
    • FREVO ON RAILS Mais um resultado do desacoplamento
    • 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
    • FREVO ON RAILS require "#{Rails.root}/lib/validadores/cep_validator" class Person < ActiveRecord::Base validates :cep, cep: true end
    • FREVO ON RAILS ACTION MAILER
    • FREVO ON RAILS Sai TMail, entra Mail
    • FREVO ON RAILS Uma nova casa para os mailers ./app/mailers/nome_do_mailer
    • FREVO ON RAILS Criação de defaults para diminuir duplicação de código
    • 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
    • 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
    • FREVO ON RAILS Anexos muito mais fáceis
    • FREVO ON RAILS class UserMailer < ActionMailer::Base ! default from: “email@example.com” ! def welcome(user) ! ! @user = user ! ! attachments[“hello.gif”] = File.read(‘...’) ! ! mail(to: user.email, ! ! ! subject: “Welcome to my site”) ! end end
    • FREVO ON RAILS class UserMailer < ActionMailer::Base ! default from: “email@example.com” ! def welcome(user) ! ! @user = user ! ! attachments.inline[“logo.png”] = ! ! ! File.read(...) ! ! mail(to: user.email, ! ! ! subject: “Welcome to my site”) ! end end
    • FREVO ON RAILS
    • FREVO ON RAILS DEMO TIME
    • FREVO ON RAILS RECURSOS
    • FREVO ON RAILS Rails Dispatch http://railsdispatch.com/
    • FREVO ON RAILS Rails Guides Edge http://guides.rails.info/
    • FREVO ON RAILS Engine Yard Blog http://www.engineyard.com/blog
    • FREVO ON RAILS Dive into Rails 3 Screencasts http://rubyonrails.org/screencasts/rails3
    • FREVO ON RAILS Railscasts http://railscasts.com/
    • FREVO ON RAILS Agile Web Development with Rails (4th ed.) http://pragprog.com/titles/rails4/agile-web-development-with-rails
    • FREVO ON RAILS The Rails 3 Way http://my.safaribooksonline.com/9780132480345
    • FREVO ON RAILS FREVO ON RAILS GRUPO DE USUÁRIOS RUBY DE PERNAMBUCO