How can I keep my initializer configuration from being lost in development mode?

后端 未结 2 1063
别那么骄傲
别那么骄傲 2021-02-18 22:24

I\'m working on a Rails app that uses an engine. I\'m using an initializer to configure one of my engine\'s controllers so that it will trigger an action in the host app. The co

2条回答
  •  滥情空心
    2021-02-18 22:56

    There's nothing to stop you from doing initializer code in a file that lives in app/models.

    for example

    class MyClass
      def self.run_me_when_the_class_is_loaded
      end
    end
    
    MyClass.run_me_when_the_class_is_loaded
    

    MyClass.run_me... will run when the class is loaded .... which is what we want, right?

    Not sure if its the Rails way.... but its extremely straightforward, and does not depend on the shifting winds of Rails.

提交回复
热议问题