Repensando o Desenvolvimento Web com Ruby on Rails

977 views

Published on

Palestra proferida no Software Freedom Day / SE - 2009

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

No Downloads
Views
Total views
977
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
20
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Repensando o Desenvolvimento Web com Ruby on Rails

    1. 1. Repensando o Desenvolvimento Web com Ruby on Rails
    2. 2. Rails
    3. 3. Comunidade
    4. 4. Filosofia
    5. 5. DanteRegis.com @danteregis Admin de Redes - TJ/SE
    6. 6. DanteRegis.com @danteregis Admin de Redes - TJ/SE http://slideshare.net/danteregis
    7. 7. Você não vai aprender Ruby on Rails aqui
    8. 8. framework
    9. 9. David Heinemeier Hansson 2004
    10. 10. 37signals
    11. 11. 1400+ desenvolvedores
    12. 12. jul/2004 0.5 dez/2005 1.0 mar/2006 1.1 jan/2007 1.2 dez/2007 2.0 jun/2008 2.1 nov/2008 2.2 mar/2009 2.3 algum dia (em 2009?) 3.0
    13. 13. Empregos (fonte: indeed.com)
    14. 14. MVC
    15. 15. opiniated
    16. 16. eXtreme Programming
    17. 17. TDD
    18. 18. REST
    19. 19. modularização
    20. 20. DRY
    21. 21. Convention over Configuration
    22. 22. KISS
    23. 23. script/console
    24. 24. Model
    25. 25. Model
    26. 26. Model
    27. 27. Model id: integer name: string price: float category_id: integer stock: integer created_at: datetime updated_at: datetime
    28. 28. Model id: integer name: string x = Product.new price: float category_id: integer stock: integer created_at: datetime updated_at: datetime
    29. 29. Model id: integer name: string x = Product.new price: float x.name = "Pão Jacó" category_id: integer stock: integer created_at: datetime updated_at: datetime
    30. 30. Model id: integer name: string x = Product.new price: float x.name = "Pão Jacó" category_id: integer x.stock = "100 stock: integer created_at: datetime updated_at: datetime
    31. 31. Model id: integer name: string x = Product.new price: float x.name = "Pão Jacó" category_id: integer x.stock = "100 stock: integer x.price = 0.15 created_at: datetime updated_at: datetime
    32. 32. Model id: integer name: string x = Product.new price: float x.name = "Pão Jacó" category_id: integer x.stock = "100 stock: integer x.price = 0.15 created_at: datetime x.save updated_at: datetime
    33. 33. Model
    34. 34. Model INSERT INTO `products` COLUMNS (`name`, `price`, `stock`) VALUES ("Pão Jaco", 0.15, 100);
    35. 35. Model
    36. 36. Model Product.first
    37. 37. Model Product.first Product.find_all_by_category_id(10)
    38. 38. Model Product.first Product.find_all_by_category_id(10) Product.find_or_create_by_name("Margarina")
    39. 39. Model Product.first Product.find_all_by_category_id(10) Product.find_or_create_by_name("Margarina") Product.count
    40. 40. Model Product.first Product.find_all_by_category_id(10) Product.find_or_create_by_name("Margarina") Product.count Product.average('price')
    41. 41. validations
    42. 42. associations
    43. 43. instance methods
    44. 44. Model class Product < ActiveRecord::Base end
    45. 45. Model class Product < ActiveRecord::Base end
    46. 46. Model class Product < ActiveRecord::Base belongs_to :category end
    47. 47. Model class Product < ActiveRecord::Base belongs_to :category validates_presence_of :name end
    48. 48. Model class Product < ActiveRecord::Base belongs_to :category validates_presence_of :name validates_numericality_of :stock end
    49. 49. Model class Product < ActiveRecord::Base belongs_to :category validates_presence_of :name validates_numericality_of :stock def consume! stock -= 1 save end end
    50. 50. p = Product.new(:stock => "xxxxx")
    51. 51. p = Product.new(:stock => "xxxxx") p.save
    52. 52. p = Product.new(:stock => "xxxxx") p.save #=> false
    53. 53. p = Product.first p.category p.category.name = "Mudei o nome" p.category.save
    54. 54. has_many
    55. 55. class Category < ActiveRecord::Base has_many :products end
    56. 56. cat.products cat.products.new cat.products.first
    57. 57. named scope
    58. 58. class Product < ActiveRecord::Base named_scope :low_stock, :conditions => ['stock <= 10'] end
    59. 59. Product.low_stock #=> [.....]
    60. 60. Product.low_stock #=> [.....] category.products.low_stock #=> [...]
    61. 61. SQL?
    62. 62. migrations
    63. 63. controle de versão
    64. 64. do banco de dados!
    65. 65. sem SQL!
    66. 66. class AddQuantityToCartProduct < ActiveRecord::Migration
    67. 67. class AddQuantityToCartProduct < ActiveRecord::Migration def self.up add_column :cart_products, :quantity, :integer end
    68. 68. class AddQuantityToCartProduct < ActiveRecord::Migration def self.up add_column :cart_products, :quantity, :integer end def self.down drop_column :cart_products, :quantity end end
    69. 69. com SQL!
    70. 70. > 90% experiência pessoal
    71. 71. ActionController
    72. 72. session
    73. 73. render
    74. 74. filters
    75. 75. class ApplicationController < ActionController::Base before_filter :check_login def check_login render :text => "acesso negado!" end end
    76. 76. flash
    77. 77. flash[:notice] = "Você logou no sistema"
    78. 78. cookies
    79. 79. respond_to
    80. 80. ActionView
    81. 81. erb
    82. 82. haml
    83. 83. erb
    84. 84. form_tag form_for
    85. 85. <div> <span><%= flash[:notice] %></span> </div> <div> <% form_tag do %> <p> Usuário: <%= text_field_tag 'username' %> </p> <p> Senha: <%= password_field_tag 'password' %> </p> <p> <%= submit_tag 'Entrar' %> </p> <% end %> </div>
    86. 86. Tempo para falar mal de certas “soluções”
    87. 87. Fim do tempo para falar mal de certas “soluções”
    88. 88. Comunidade
    89. 89. RailsConf http://railsconf.com
    90. 90. Rails Summit Latin America http://railssummit.com.br
    91. 91. 13 e 14 de outubro São Paulo/SP
    92. 92. Aldo França
    93. 93. Great Blogs ‘n People
    94. 94. Akita on Rails http://akitaonrails.com
    95. 95. Carlos Brando http://nomedojogo.com
    96. 96. Ozéias Sant’ana http://railsbox.org
    97. 97. Bruno Miranda http://brunomiranda.com
    98. 98. Ruby Onda http://rubyonda.com
    99. 99. Nando Vieira http://simplesideias.com.br
    100. 100. PeepCode http://peepcode.com
    101. 101. RailsCasts http://railscasts.com
    102. 102. http://slideshare.net/danteregis
    103. 103. dante@danteregis.com

    ×