将独立的Ruby文件添加到Ruby on Rails项目中(Adding standalone Ruby Files to a Ruby on Rails project)

编程入门 行业动态 更新时间:2024-10-24 13:32:21
独立的Ruby文件添加到Ruby on Rails项目中(Adding standalone Ruby Files to a Ruby on Rails project)

我有一个ruby on rails项目,包括脚手架,视图,布局,模型等。 我还有一些独立的ruby(.rb)文件,我希望在我的上述项目中包含这些文件。 是否可以通过将这些方法放在某处并从控制器中调用它们来简单地调用这些rb文件中定义的这些方法?

如果没有,我怎么去添加它们?

任何帮助将非常感谢,谢谢

I have a ruby on rails project with scaffolding , views, layouts, models and such. I also have some standalone ruby (.rb) files which i would like to include in my afforementioned project. Is it possible to simply call these methods defined in these rb files by placing them somewhere and calling them from the controller or so?

If not, how can i go about and add them?

Any assistance would be highly appreciated thanks

最满意答案

将代码放在lib文件夹中,然后在config/initializers创建一个新的初始化文件,并需要你想要的文件。

Place your code in the lib folder, then create a new initializer file in config/initializers and require the files u want.

更多推荐

rb,ruby,文件,project,files,电脑培训,计算机培训,IT培训"/> <meta name="desc

本文发布于:2023-08-03 14:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391355.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:独立   文件   项目   Files   Ruby

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!