Search
⌘K
    to navigateEnterto select Escto close

    Ensure for before_action

    It's common to have code like this in controllers:

    1class HomeController < ApplicationController
    2  before_action :ensure_car_exists, only: [:index]
    3end

    Note that, in this case, the method name is ensure_car_exists. Another possible name for it could be verify_car_exists.

    Both names are good names - however, we have adopted a convention that such method names should start with ensure_.

    Another example

    1class HomeController < ApplicationController
    2  before_action :authenticate_admin
    3end

    :authenticate_admin is a perfectly valid name. However, we prefer before_action :ensure_user_is_admin.

    Previous
    Next