Introdução ao Ruby on Rails

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Introdução ao Ruby on Rails - Presentation Transcript

    1. Introdução ao Ruby on Rails Introdução ao Ruby on Rails
    2. Juan Maiz Lulkin Flores da Cunha Introdução ao Ruby on Rails > Palestrante WWR person/9354 vice-campeão mundial de defender of the favicon
    3. História David Heinemeier Hanson (DHH) Martin Fowler 37Signals Introdução ao Ruby on Rails > História
    4. Ruby on Rails Ruby Model View Controller Princípios Comunidade And so much more Introdução ao Ruby on Rails > Ruby on Rails
    5. Ruby Smalltalk elegância conceitual Python facilidade de uso Perl pragmatismo Introdução ao Ruby on Rails > Ruby on Rails > Ruby
    6. Smalltalk 1 + 1 => 2 1.+(1) => 2 1.send('+',1) => 2 Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Smalltalk
    7. Python for 1 in 1..10 puts i end 1 2 3 4 5 6 7 Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Python
    8. Perl ls = %w{smalltalk python perl} => ["smalltalk", "python", "perl"] ls.map{|l| “Ruby é como #{l}. ” }.join => “Ruby é como smalltalk. Ruby é como python. Ruby é como perl. Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Perl
    9. Ruby 5.times{ p “ybuR olleH”.reverse } "Hello Ruby" "Hello Ruby" "Hello Ruby" "Hello Ruby" "Hello Ruby" => 5 Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Hello
    10. Ruby Totalmente OO Mixins (toma essa!) Classes “abertas” Blocos Bibliotecas Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Conceitos
    11. Totalmente OO 42.class => Fixnum Fixnum.class => Class Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Conceitos > Totalmente OO
    12. Mixins (toma essa!) module Cool def is_cool! “ #{self} is cool!” end end Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Conceitos > Mixins (toma essa!)
    13. Classes “abertas” class String include Cool end puts “Ruby”.is_cool! Ruby is cool! Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Conceitos > Classes “abertas”
    14. Blocos [16,19,21,15].select{|n| n > 17} => [19,21] [1,2,3].map{|n| n*2 } => [2,4,6] [5,6,7,8].sort_by{ … } File.open('file.txt').each_line{ … } Dir.glob('*.rb').each{ … } Benchmark.measure { ... } Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Conceitos > Blocos
    15. Bibliotecas Hpricot + OpenUri Hpricot(open 'http://ab.com').search('a').map{|a| a[:href]} Prawn Prawn::Document.new.text(“Hello PDF”) RedCloth RedCloth.new(“Hello *Textile*”).to_html RMagick Image.read('i.pdf').first.write('i.png'){self.quality = 80} Shoes Shoes.app{ button "Hello Windows" } RubyGame Game.new.when_key_pressed(:q){ exit } Geokit YahooGeocoder.geocode 'Rua Vieira de Casto 262' Introdução ao Ruby on Rails > Ruby on Rails > Ruby > Conceitos > Bibliotecas
    16. Model View Controller Model dados e lógica de domínio View interface Controller caminhos e distribuição Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller
    17. Model ActiveRecord Migrações Operações básicas Relações Validações Acts as Named scopes Adicionar métodos Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model
    18. Migrações class CreateEvents < ActiveRecord::Migration def self.up create_table :events do |t| t.string :name, :null => false t.boolean :active, :default => true t.integer :year, :null => false t.timestamps end end end Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Migrações
    19. Operações básicas Insert Event.create :name => 'RS on Rails', :year => Date.today.year e = Event.new e.name = 'RS on Rails' e.year = 2009 e.save Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Operações básicas
    20. Operações básicas Select Event.all :conditions => 'active', :order => 'created_at', :limit => 10 e = Event.first e = Event.find 1 e = Event.find_by_name 'RS on Rails' e = Event.find_by_year 2009 Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Operações básicas
    21. Operações básicas Update Event.update_all 'active = true' e = Event.first e.name = 'other name' e.save e.update_attribute :active => false e.toggle! :active Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Operações básicas
    22. Operações básicas Delete Event.delete_all e = Event.first e.destroy Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Operações básicas
    23. Relações class Event < ActiveRecord::Base has_many :talks end class Talk < ActiveRecord::Base belongs_to :event has_one :speaker end Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Relações
    24. Relações rsr = Event.find_by_name('rsrails') talk = rsr.talks.first talk.name => “Introdução ao Ruby on Rails” talk.speaker.name => “Juan Maiz Lulkin” Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Relações
    25. Validações class Event < ActiveRecord::Base validates_presence_of :name, :year validates_numericality_of :year validates_inclusion_of :year, :in => 2009..2099 validates_length_of :name, :minimum => 4 validates_format_of :name, :with => /[A-Z]d+/ end Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Validações
    26. Acts As class Category < ActiveRecord::Base acts_as_tree enb Category.find(10).parent Category.find(20).children Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Acts as
    27. Acts As class Doc < ActiveRecord::Base acts_as_versioned end doc = Doc.create :name = '1 st name' doc.version => 1 doc.update_attribute :name, '2 nd name' doc.version => 2 doc.revert_to(1) doc.name => 1 st name Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Acts as
    28. Named scopes class Product < ActiveRecord::Base named_scope :top, :order => 'rank desc' named_scope :ten, :limit => 10 named_scope :between, lambda{|min,max| {:conditions => [“price between ? and ?”, min, max]}} end Product.between(0,100).top.ten Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Named scopes
    29. Adicionar métodos class Product < ActiveRecord::Base def +(product) price + product.price end end foo = Product.find(1) bar = Product.find(2) foo + bar Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Model > Adicionar métodos
    30. Controller URL: http://seusite.com/events/rsrails class EventsController < ApplicationController def show name = params[:id] @event = Event.find_by_name(name) end end Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Controller
    31. View app/views/events/show.html.haml #content %h1 Palestras %ul - for talk in @event.talks %li= talk.title * Você está usando HAML, não? Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > View
    32. Princípios Convention Over Configuration Se é usado na maior parte dos casos, deve ser o padrão. Don't Repeat Yourself Mixins, plugins, engines, gems... Métodos ágeis BDD, TDD, integração contínua, deployment... Introdução ao Ruby on Rails > Ruby on Rails > Princípios
    33. Convention Over Configuration XML YAML development: adapter: postgresql encoding: unicode database: events_development pool: 5 username: event_admin password: ***** Introdução ao Ruby on Rails > Ruby on Rails > Princípios > CoC
    34. Convention Over Configuration rsrails = Event.find(1) => assume campo “id” na tabela “events” rsrails.talks => assume uma tabela “talks” com um fk “event_id” rsrails.talks.first.speaker => assume campo “speaker_id” em “talks” como fk para tabela “speakers” Introdução ao Ruby on Rails > Ruby on Rails > Princípios > CoC
    35. Convention Over Configuration script/generate scaffold Event name:string year:integer active:boolean Introdução ao Ruby on Rails > Ruby on Rails > Princípios > CoC
    36. Don't Repeat Yourself active_scaffold link_to login image_tag 'star.png' * hotel.stars render :partial => 'event', :collection => @events Introdução ao Ruby on Rails > Ruby on Rails > Princípios > DRY
    37. Métodos ágeis class EventTest < ActiveSupport::TestCase test &quot;creation&quot; do assert Event.create :name => 'rsrails', :year => 2009 end end Introdução ao Ruby on Rails > Ruby on Rails > Princípios > Métodos ágeis
    38. Métodos ágeis rake integrate cap deploy Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Princípios > Métodos ágeis
    39. Métodos ágeis Getting Real http://gettingreal.37signals.com/ Introdução ao Ruby on Rails > Ruby on Rails > Model View Controller > Princípios > Métodos ágeis
    40. Comunidade Lista rails-br Ruby Inside (.com e .com.br) Working With Rails Introdução ao Ruby on Rails > Ruby on Rails > Comunidade
    41. And so much more Internacionalização (i18n) Rotas Cache Ajax Background Jobs ... Introdução ao Ruby on Rails > Ruby on Rails > And so much more
    42. Fim Introdução ao Ruby on Rails > Fim

    + Juan MaizJuan Maiz, 2 months ago

    custom

    297 views, 0 favs, 1 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 297
      • 263 on SlideShare
      • 34 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 3
    Most viewed embeds
    • 34 views on http://blog.softa.com.br

    more

    All embeds
    • 34 views on http://blog.softa.com.br

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories