Skip to main content

controller

Controller

Its a good practice to namespace your controllers. For example:-

❌ Bad Practice

class TransactionController < ApplicationController
def create_payment
end

def edit_payment
end

def report_payment
end

def refund
end

def edit_refund
end

def report_refund
end
end

✅ Good Practice

controllers
|-> transactions
|-> payments_controller.rb
|-> refunds_controller.rb

And after that have CRUD actions/methods within these individual controllers.

In addition to ☝️ , here are few things to keep in mind when working within the controllers:-

  1. Always be restful (CRUD)
  2. Security first, if the action/s defined are supposed to be accessed only by logged in user/admin/support/affiliates or any of the permissions, pease make sure to secure it.
  3. If any of the helper methods are used multiple times, please make sure to create a concern instead of repeating them.
  4. Please try to keep it skinny, make it maintainable and easy to understand. Complex and long business logics should go to [[Interactors]] instead.