Ruby on Rails na Unip

1,252 views

Published on

Adaptação da minha palestra na InfoQ e na Campus Party para o grupo .Net Architects que se encontra na Unip. http://www.dotnetarchitects.net/ Foi muito legal.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,252
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Ruby on Rails na Unip

  1. 1. Ruby on Rails
  2. 2. AkitaOnRails.com
  3. 3. http://www.akitaonrails.com
  4. 4. http://www.locaweb.com.br/rails
  5. 5. 1
  6. 6. Joel Spolsky
  7. 7. “Without understanding functional programming, you can't invent MapReduce, the algorithm that makes Google so massively scalable.” “The Perils of JavaSchools” - Joel Spolsky - 29/12/2005 http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html
  8. 8. “The terms Map and Reduce come from Lisp and functional programming...” “The Perils of JavaSchools” - Joel Spolsky - 29/12/2005 http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html
  9. 9. “The very fact that Google invented MapReduce, and Microsoft didn't, says something about why Microsoft is still playing catch up.” “The Perils of JavaSchools” - Joel Spolsky - 29/12/2005 http://www.joelonsoftware.com/articles/ThePerilsofJavaSchools.html
  10. 10. Codificadores x Desenvolvedores
  11. 11. “SOFT”WARE
  12. 12. AGILIDADE
  13. 13. Estamos “descobrindo” maneiras melhores de desenvolver software na prática e ajudando outros a desenvolver.
  14. 14. Big Design Up Front
  15. 15. Big Design Up Front
  16. 16. Escopo Fechado
  17. 17. Escopo Fechado
  18. 18. Faseamento em Cascata
  19. 19. Faseamento em Cascata
  20. 20. “Change Request”
  21. 21. “Change Request”
  22. 22. Ceticismo
  23. 23. Winston W. Royce - 1970
  24. 24. “I believe in this concept, but the implementation described above is risky and invites failure.” Winston W. Royce - 1970
  25. 25. “I believe in this concept, but the implementation described above is risky and invites failure.” Winston W. Royce - 1970
  26. 26. “I believe in this concept, but the implementation described above is risky and invites failure.” Winston W. Royce - 1970
  27. 27. “Cargo Cult”
  28. 28. 2
  29. 29. “Matz” 1993 http://www.ruby-lang.org
  30. 30. “Prag Dave” 2001 http://www.rubycentral.com/book/ http://www.pragprog.com/titles/ruby3/programming-ruby-1-9
  31. 31. “DHH” 2004 http://www.rubyonrails.org http://www.loudthinking.com
  32. 32. http://rubyonrails.org/screencasts
  33. 33. http://rubyonrails.org/screencasts
  34. 34. “Tornar as coisas simples fáceis e as coisas complexas possíveis” Filosofia Ruby
  35. 35. http://www.levenez.com/lang/
  36. 36. Ruby on Rails
  37. 37. RUBY http://guides.rails.info/
  38. 38. ActiveSupport Rails RUBY http://guides.rails.info/
  39. 39. ActionController ActionPack ActionView ActiveSupport Rails RUBY http://guides.rails.info/
  40. 40. ActiveRecord ActionController ActionPack ActionView ActiveSupport Rails RUBY http://guides.rails.info/
  41. 41. ActionMailer ActiveRecord ActionController ActionPack ActionView ActiveSupport Rails RUBY http://guides.rails.info/
  42. 42. ActiveResource ActionWebService ActionMailer ActiveRecord ActionController ActionPack ActionView ActiveSupport Rails RUBY http://guides.rails.info/
  43. 43. RSpec describe Product do include ProductSpecHelper before(:each) do @product = Product.new end it quot;should not be valid when emptyquot; do @product.should_not be_valid end it quot;should be valid when having correct informationquot; do @product.attributes = valid_product_attributes @product.should be_valid end end
  44. 44. RSpec describe Product do include ProductSpecHelper before(:each) do @product = Product.new end it quot;should not be valid when emptyquot; do rake spec @product.should_not be_valid end it quot;should be valid when having correct informationquot; do @product.attributes = valid_product_attributes @product.should be_valid end end
  45. 45. Model class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties belongs_to :tax_category validates_presence_of :name validates_presence_of :master_price validates_presence_of :description make_permalink :with => :name, :field => :permalink end
  46. 46. Model class Product < ActiveRecord::Base after_create :set_initial_inventory has_many :variants, :dependent => :destroy has_many :images, :as => :viewable, :order => :position, :dependent => :destroy has_many :properties, :through => :product_properties Product.find(1) belongs_to :tax_category validates_presence_of :name validates_presence_of :master_price validates_presence_of :description make_permalink :with => :name, :field => :permalink end
  47. 47. Controller class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) .find_all_by_user_id(current_user.id) end create.after { self.current_user = @user } create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end
  48. 48. Controller class UsersController < Spree::BaseController resource_controller before_filter :initialize_extension_partials actions :all, :except => [:index, :destroy] show.before do @orders = Order.checkout_completed(true) /users/1 .find_all_by_user_id(current_user.id) end create.after { self.current_user = @user } create.response do |wants| wants.html { redirect_back_or_default(products_path) } end end
  49. 49. Views ERB <div id=quot;product-listingquot;> <%= breadcrumbs(@taxon) %> <br/> <%= render :partial => quot;shared/products.html.erbquot;, :locals => {:products => @products, :taxon => @taxon } %> </div> <% content_for :sidebar do %> <td id=quot;shop-by-colquot; valign=quot;topquot;> <%= render :partial => quot;shared/taxonomiesquot; %> </td> <% end %> <%= render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty? %>
  50. 50. Views HAML #product-listing =breadcrumbs(@taxon) %br =render :partial => quot;shared/products.html.erbquot;, :locals => {:products => @products, :taxon => @taxon} -content_for :sidebar do %td#shop-by-col(:valign => quot;topquot;) =render :partial => quot;shared/taxonomiesquot; =render :partial => 'shared/paginate', :locals => {:collection => @products, :options => {}} unless @products.empty?
  51. 51. Rotas RESTFul ActionController::Routing::Routes.draw do |map| map.connect ':controller/service.wsdl', :action => 'wsdl' map.resources :products, :member => {:change_image => :post} map.resources :addresses map.resources :orders, :has_many => [:line_items] map.namespace :admin do |admin| admin.resources :users admin.resources :products end end
  52. 52. Rotas RESTFul ActionController::Routing::Routes.draw do |map| GET /products/new map.connect ':controller/service.wsdl', :action => 'wsdl' GET /products map.resources :products, POST /products :member => {:change_image => :post} map.resources :addresses GET /products/1 map.resources :orders, GET /products/1/edit :has_many => [:line_items] map.namespace PUT /products/1 :admin do |admin| DESTROY /products/1 admin.resources :users admin.resources :products end end
  53. 53. Migrations class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end end def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations end end
  54. 54. Migrations class RenameAppConfiguration < ActiveRecord::Migration def self.up rename_table :app_configurations, :configurations change_table :configurations do |t| t.string :type end rake db:migrate end def self.down change_table :configurations do |t| t.remove :type end rename_table :configurations, :app_configurations end end
  55. 55. “Beautiful Code”
  56. 56. http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programming http://weblog.jamisbuck.org/2008/11/29/recovering-from-enterprise-video-available
  57. 57. 11 mil classes! 46 só de Collections! http://weblog.jamisbuck.org/2008/11/9/legos-play-doh-and-programming http://weblog.jamisbuck.org/2008/11/29/recovering-from-enterprise-video-available
  58. 58. • Classes: • Modules: • Array • Enumerable • Hash • Comparable • Set • Sorted Set
  59. 59. 1.400Classes: • classes • Modules: • Array • Enumerable • Hash • Comparable 6 deSet só • Collections! Set • Sorted
  60. 60. • Convention over Configuration • Don’t Repeat Yourself • You Ain’t Gonna Need It • Automação • Boas Práticas • Código Bonito • Ferramentas Simples
  61. 61. http://macromates.com http://www.apple.com/macbook
  62. 62. 3
  63. 63. Mitos http://www.loudthinking.com/posts/29-the-rails-myths
  64. 64. Rails não Escala
  65. 65. FUD: http://www.techcrunch.com/2008/05/22/twitter-at-scale-will-it-work/
  66. 66. To put things into perspective, though, Friendster was written in Java to start, and switched to PHP. Myspace was written in ColdFusion and transitioned to ASP.NET. When people run into problems scaling sites they often think that the language is the problem, but I think it’s Blaine Cook rarely the case. http://www.akitaonrails.com/2008/6/17/chatting-with-blaine-cook-twitter http://www.akitaonrails.com/2008/6/17/chatting-with-blaine-cook-twitter
  67. 67. “The New York Times used Ruby on Rails to pull together, analyze and display election results in near real time on one of its busiest Web traffic days ever. ” http://www.computerworld.com.au/article/268003/ruby_rails_rolls_into_enterprise?fp=16&fpid=1 http://www.computerworld.com/action/article.do? command=viewArticleBasic&articleId=9120778
  68. 68. “They serve up 23 million visitors a month. The conversion resulted in 20,000 lines of Ruby code instead of 125,000 lines of Java code, and most importantly eased the difficulty they had in maintaining it. Once complete, and optimized their site is now faster than before. They also completed the rewrite in three months with four developers.” http://www.railsonwave.com/railsonwave/2008/6/4/yellowpages-com-migrates-to-rails http://www.akitaonrails.com/2008/11/21/rails-podcast-brasil-qcon-special-john-straw- yellowpages-com-and-matt-aimonetti-merb http://www.rubyonrailsexamples.com/sites-on-rails/yellowpagescom-goes-ror/
  69. 69. http://www.techcrunch.com/2008/01/24/hulu-discusses-private-beta-suggests-public- launch-time-frame/
  70. 70. http://www.blogblogs.com.br
  71. 71. Mitos
  72. 72. Deployment de Rails é difícil
  73. 73. Apache + FastCGI LightTPD + FastCGI Litespeed + SAPI Apache + Mongrel Nginx + Mongrel Nginx + Thin
  74. 74. Apache + FastCGI LightTPD + FastCGI Litespeed + SAPI Apache + Mongrel Nginx + Mongrel Nginx + Thin
  75. 75. Apache + FastCGI LightTPD + FastCGI Litespeed + SAPI Apache + Mongrel Nginx + Mongrel Nginx + Thin
  76. 76. Apache + FastCGI LightTPD + FastCGI Litespeed + SAPI Apache + Mongrel Nginx + Mongrel Nginx + Thin
  77. 77. Apache + FastCGI LightTPD + FastCGI Litespeed + SAPI Apache + Mongrel Nginx + Mongrel Nginx + Thin
  78. 78. Apache + FastCGI LightTPD + FastCGI Litespeed + SAPI Apache + Mongrel Nginx + Mongrel Nginx + Thin
  79. 79. http://phusion.nl http://www.modrails.com/
  80. 80. gem install passenger passenger-install-apache2-module http://phusion.nl http://www.modrails.com/
  81. 81. Mitos
  82. 82. Rails é mal documentado
  83. 83. Geoffrey http://www.peepcode.com
  84. 84. Jason e Gregg http://railsenvy.com http://envycasts.com
  85. 85. Ryan Bates http://railscasts.com
  86. 86. Pratik Naik http://guides.rails.info/
  87. 87. Satish Talim http://rubylearning.org
  88. 88. Peter Cooper http://rubyinside.com http://railsinside.com http://rubyflow.com http://jrubyinside.com
  89. 89. _why http://whytheluckysti.net/
  90. 90. http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooksfield-keywords=ruby+railsx=0y=0
  91. 91. 4
  92. 92. Open Source
  93. 93. Chris Wanstrath http://github.com
  94. 94. http://rubyforge.org http://gitorious.org
  95. 95. http://jruby.codehaus.org http://www.macruby.org http://www.ironruby.net http://ruby.gemstone.com/
  96. 96. http://gettingreal.37signals.com/GR_por.php http://aprendaaprogramar.rubyonrails.pro.br/ http://why.nomedojogo.com/ http://rubyonrails.pro.br
  97. 97. http://gettingreal.37signals.com/GR_por.php http://aprendaaprogramar.rubyonrails.pro.br/ http://why.nomedojogo.com/ http://rubyonrails.pro.br
  98. 98. Conferências
  99. 99. http://www.confreaks.com/ http://www.akitaonrails.com/railsconf2008
  100. 100. http://www.locaweb.com.br/railssummit http://www.akitaonrails.com/railssummit2008
  101. 101. Especialista de uma coisa só é um amador em todo o resto.
  102. 102. Obrigado! www.akitaonrails.com

×