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

5 basic tips for RubyOnRails projects

5 basic tips for RubyOnRails projects

Nando Sousa

July 08, 2015
Tweet

More Decks by Nando Sousa

Other Decks in Programming

Transcript

  1. <!-- app/views/checkout/index.html.erb --> ... <div class="address"> ... 15 lines </div>

    <!-- .address --> <div class="delivery"> ... 20 lines </div> <!-- .delivery --> <div class="summary"> ... 50 lines </div> <!-- .summary --> <div class="payment"> ... 60 lines </div> <!-- .payment -->
  2. <!-- app/views/checkout/index.html.erb --> <!-- app/views/checkout/_address.html.erb --> <%= render 'address', address:

    @customer.address %> <!-- app/views/checkout/_delivery.html.erb --> <%= render 'delivery' %> <!-- app/views/checkout/_summary.html.erb --> <%= render 'summary' %> <!-- app/views/checkout/_payment.html.erb --> <%= render 'payment' %>
  3. 4 Controllers can instantiate only one object. Therefore, views can

    only know about one instance variable and views should only send messages to that object (@object.collaborator.value is not allowed). 2 Methods can be no longer than five lines of code. 3 Pass no more than four parameters into a method. Hash options are parameters. 1 Classes can be no longer than one hundred lines of code.
  4. “You should break these rules only if you have a

    good reason or your pair lets you.”
  5. Return appropriate status codes on Responses 200: Request succeeded for

    a GET call, for a DELETE or PATCH call that completed 201: Request succeeded for a POST call that completed synchronously, or for a PUT call that synchronously created a new resource 202: Request accepted for a POST, PUT, DELETE, or PATCH call that will be processed asynchronously