简体   繁体   English

Rails初始化程序在哪里进入gem?

[英]Where does the Rails initializer go in a gem?

I'm trying to extract some functionality from my existing app into a gem. 我正在尝试从现有应用程序中提取一些功能到gem中。 The existing functionality uses an initializer to load up a config file when Rails starts up... 当Rails启动时,现有功能使用初始化程序加载配置文件...

config/initalizers/myinitializer.rb

Where should this initializer go in the gem? 这个初始化器应该放在哪里? Do I mirror the path structure inside the gem or put it somewhere else? 我是否镜像宝石内部的路径结构或将其放在其他地方? This will be my first gem. 这将是我的第一个宝石。

When the Gem is loaded, Rails first looks for a file called init.rb in the main Gem folder and requires it if available. 加载Gem时,Rails首先在主Gem文件夹中查找名为init.rb的文件,如果可用则需要它。

This can be a super-simple base skeleton for a Rails plugin packages as Gem: 对于像Gem这样的Rails插件包,这可以是一个超级简单的基础框架:

name
name/lib
name/lib/name.rb
name/test
name/init.rb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM