【问题标题】:Perform Action on Rails App Close在 Rails 应用关闭时执行操作
【发布时间】:2012-02-19 18:16:53
【问题描述】:

当 Rails 应用程序关闭时,遵循的过程是什么?我怎样才能使用它来清理在 Rails 应用程序运行期间创建的文件?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.2


    【解决方案1】:

    您可以将以下代码块添加到config/boot.rb 以在应用关闭时运行命令:

    at_exit do
      puts "Shutting the app down..."
    end
    

    这是您将在服务器进程中看到的输出:

    [Swanny ~/Sites/test_app]$ bundle exec thin start
    >> Using rack adapter
    >> Thin web server (v1.3.1 codename Triple Espresso)
    >> Maximum connections set to 1024
    >> Listening on 0.0.0.0:3000, CTRL+C to stop
    ^C>> Stopping ...
    Shutting the app down...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-19
      相关资源
      最近更新 更多