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

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

29 slides
  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

More Decks by Mario Alberto Chávez

Other Decks in Programming