Rails applications' life cycle

后端 未结 4 2142
甜味超标
甜味超标 2021-01-30 14:11

I\'m trying to learn the life cycle of a rails application. When is application_controller.rb run? Is it just once every time it\'s changed, or on every request?

I want

4条回答
  •  無奈伤痛
    2021-01-30 14:51

    Here is what I observed by putting a bunch of print statements in the code:

    The application_controller and the posts_controller (for example) are "run" on each request. Every line of code not inside a method def/end is executed in both controllers, and then code flow passes to the requested/routed method.

    As this is not what I expected I thought it worthwhile to post it. If I'm wrong pls feel free to edit.

    With Heroku, print statement output only shows up in the stdout log if the print statement is inside a method, for some reason. But I believe the above description still applies.

提交回复
热议问题