I have a controller named HomeController
with index
and show
actions. I want to check if the user subscription has ended and show him a message and redirect to HomeController#index
.
Currently i am doing it as below
class HomeController < ApplicationController
before_action :check_if_trial_expired, only: [:index]
before_action :redirect_if_trial_expired, only: [:show]
protected
def check_if_trial_expired
@trial_expired = current_user.trial_expired?
end
def redirect_if_trial_expired
redirect_to home_path if current_user.trial_expired?
end
end
Is there a better way to do this? I want to redirect the user to HomeController#index
in case a condition satisfies.
Many Thanks in advance.