简体   繁体   中英

How to determine the caller of a before_action

I have a before_action that is called for user authentication and other features. But there is some functionality in the before_action that depends on the caller. I don't want to separate the logic into two before_actions and use a skip_before_action; as large parts of the before_action must be executed in any case.

How can I determine the calling controller and method of the before_action?

Do you think that a caller of a before_action is that action? This is not so. But, perhaps, you do need to find the caller. In this case, use caller . It'll return you a stack trace, which you can filter as you wish.

To find the action, use params[:action] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM