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

Beyond the Rails Way

Beyond the Rails Way

As Rails applications grow, maintainability and testability becomes a real challenge. It is time to move beyond the Rails Way and explore new ways to organize your application.

Mario Alberto Chávez

June 02, 2017
Tweet

More Decks by Mario Alberto Chávez

Other Decks in Programming

Transcript

  1. michelada.io scope :active -> { where(status: :active) }
 scope :with_orders

    -> { includes(:orders) } scope :ordered -> { order(created_at: :desc) } @products = Product. active. with_orders. ordered. where(color: :red)
  2. michelada.io class ProductQuery def self.execute(scope: Product, *params)
 …
 end
 #

    more complex logic
 … 
 end @products = ProductQuery.execute(
 ordered: true, with_orders: true )
  3. michelada.io class Product < ApplicationRecord include Flaggable include Taggable include

    Conflictable include Measurable include Sanitizable include Searchable include Permisionable end
 
 Product.methods(false).count #=> 161
  4. michelada.io class ProductPermissions def self.can_save?(product:, user:) … end # more

    methods related to permissions … end if ProductPermissions.can_save?(@product, @me) … end
  5. michelada.io class ProductPresenter < SimpleDelegator def formatted_price … end end

    @presenter = ProductPresenter.new(@product) <%= @presenter.formatted_price %>
  6. michelada.io class ProductsController < ApplicationController def create …
 if @product.valid?


    return redirect_to …
 end
 return render :new
 … end end
  7. michelada.io - app - models - controllers - views -

    presenters - queries - actions - use_cases