Check out example codes for "rails before_action". It will help you in understanding the concepts better.

Code Example 1

before_action :run_method, only: [:index, :show]

Learn ReactJs, React Native from akashmittal.com