Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Poderosas Interfaces Rails

Poderosas Interfaces Rails

Esta palestra aborda boas práticas na modelagem de aplicações Rails. São apresentadas algumas técnicas que auxiliam na criação de componentes de baixo acoplamento, facilitando o desenvolvimento e manutenção destes componentes, diminuindo o tempo de execução de seus testes unitários e proporcionando uma experiência mais prazerosa no desenvolvimento de aplicações complexas utilizando Ruby e Rails.

Carlos Souza

August 30, 2012
Tweet

More Decks by Carlos Souza

Other Decks in Technology

Transcript

  1. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  2. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end Client
  3. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end Client Interface
  4. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end Client
  5. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  6. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  7. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  8. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment,success: 'You are now subscribed!') else render :index end end end
  9. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment,success: 'You are now subscribed!') else render :index end end end Baixa Granularidade
  10. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment,success: 'You are now subscribed!') else render :index end end end
  11. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  12. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  13. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  14. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.place redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  15. class Payment < ActiveRecord::Base protected :save ## # Add your

    comments here. # Really. ## def place end end
  16. <h2>Usuários Registrados</h2> <div class="users"> <ul> <% User.recent.paginate(@page).each do |user| %>

    <li><%= link_to(user.full_name, user) %></li> <% end %> </ul> </div>
  17. <h2>Registered Users</h2> <div class="users"> <ul> <% User.recent.paginate(@page).each do |user| %>

    <li><%= link_to(user.full_name, user) %></li> <% end %> </ul> </div>
  18. <h2>Registered Users</h2> <div class="users"> <ul> <% @users.each do |user| %>

    <li><%= link_to(user.full_name, user) %></li> <% end %> </ul> </div>
  19. <h2>Usuários Registrados</h2> <div class="users"> <ul> <% @users.each do |user| %>

    <li><%= link_to(user.full_name, user) %></li> <% end %> </ul> </div>
  20. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  21. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.save redirect_to(payment,success: 'You are now subscribed!') else render :index end end end
  22. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.place redirect_to(payment,success: 'You are now subscribed!') else render :index end end end
  23. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.place redirect_to(payment,success: 'You are now subscribed!') else render :index end end end fazendo muita coisa
  24. class PaymentsController < ApplicationController def create payment = Payment.new(params[:payment]) if

    payment.place redirect_to(payment,success: 'You are now subscribed!') else render :index end end end
  25. class PaymentsController < ApplicationController def create payment = Payment.build_with(params[:payment]) if

    payment.place redirect_to(payment,success: 'You are now subscribed!') else render :index end end end
  26. class PaymentsController < ApplicationController def create payment = Payment.build_with(params[:payment]) if

    payment.place redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  27. class PaymentsController < ApplicationController def create payment = Payment.build_with(params[:payment]) if

    payment.place redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  28. class PaymentsController < ApplicationController def create payment = Payment.build_with(params[:payment]) if

    payment.place redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  29. class PaymentsController < ApplicationController def create payment = Payment.build_with(params[:payment]) if

    payment.place redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  30. class PaymentsController < ApplicationController def create payment = Payment.build_with(params[:payment]) if

    payment.place redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  31. class PaymentsController < ApplicationController def create plan_subscriber = PlanSubscriber.build_for(current_user) if

    plan_subscriber.subscribe(params[:payment]) payment = plan_subscriber.payment redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  32. class PaymentsController < ApplicationController def create plan_subscriber = PlanSubscriber.build_for(current_user) if

    plan_subscriber.subscribe(params[:payment]) payment = plan_subscriber.payment redirect_to(payment, success:'You are now subscribed!') else render :index end end end
  33. 0 2 Rails out-of-the-box Não utilizar classes AR::Base nos controllers

    1 Não utilizar métodos AR::Base nos controllers Pirâmide de complexidade de models
  34. "Bons sistemas orientados a objeto focam em como as suas

    diferentes partes se comunicam, e não nas propriedades internas e comportamento dessas partes." Alan Kay