Check out example codes for "run method before rails". 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