Sinatra:在启动或重新启动我的应用程序时执行代码
我想在应用程序启动时执行一些 ruby 代码。实际上,这是一些用于创建我的所有表(如果它们尚不存在)的 SQL。
现在我应该手动运行我的sql(创建普通的新表),但我想在我的helloworld.rb sql中的某个地方编写,一旦我的应用程序启动或重新启动,它将执行sql。
谢谢
I want to execute some ruby code on the start of application. Actualy this is some SQL for creating all my tables if they are not already exists.
Nowaday I should run my sql manualy (creating new tables ordinary), but I want to write somewhere in my helloworld.rb sql, which will execute sql once my app is started or restarded.
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需将其放在 get/post 方法之前即可。
此代码始终在启动时解释,并且仅在启动时解释
此代码仅启动一次我的打印。
You just need place it before your get/post method.
This code is allways interpret in starting and only in starting
This code launch only one times my print.