Rails 3 loading all models on startup

后端 未结 3 1424
情书的邮戳
情书的邮戳 2021-02-05 18:32

I have a class method mixed in to all my models. the method gets called when the model class is evaluated. unfortunately (for me), this seems to be on-demand, whenever the model

3条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 18:54

    In MVC concept models are not intended to act by themselves, i.e. they should only act when controller sends them a message (for example, @foo.register_acl). Model instances even should not exist until they are created by controller.

    What are you trying to achieve with your register_acl method?

    If you really need something to be executed on object creation you can use initialize() method which is called whenever a Ruby object is created.

    However if you need model to execute some code by itself you are most likely facing some code smell and you need to change something within your app.

提交回复
热议问题