如何为 Sinatra 编写扩展而不将其打包为 gem?
我想在 sinatra 应用程序中包含 distance_of_time_in_words 方法,
我不想打包和分发 gem,而这正是 Sintra 文档指示您要做的事情。我只是希望在我看来该方法可以访问。
做到这一点最简单的方法是什么?谢谢。
I want to include the distance_of_time_in_words method in a sinatra app
I don't want to package and distribute a gem, which is what the Sintra docs direct you to do. I just want that method accessible in my view.
What's the easiest way to do this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 http://www.sinatrarb.com/intro.html 上查看 Helpers 部分并定义用于路由处理程序和模板的辅助方法
On http://www.sinatrarb.com/intro.html look at Helpers section and define helper methods for use in route handlers and templates
只需将该文件放置在 ruby 加载路径 (
$LOAD_PATH
) 中的某个位置并需要它即可。或者将代码直接放入您的应用程序文件中。Just place the file somewhere in your ruby load path (
$LOAD_PATH
) and require it. Or place the code directly in your app file.