简体   繁体   English

如何从site_ruby目录加载Rails插件?

[英]How to load a Rails plugin from the site_ruby dir?

I have a plugin (called XYZ) installed in 我在其中安装了一个插件(称为XYZ)

/usr/lib/ruby/site_ruby/1.8/XYZ

Please note its not a rubygem but the "native" ruby sitelib library. 请注意,它不是rubygem,而是“本机” ruby​​ sitelib库。 Now. 现在。

I have added this line to the config/environment.rb: 我已将此行添加到config / environment.rb中:

config.gem "XYZ"

The problem here is Rails is not loading the plugin. 这里的问题是Rails没有加载插件。 Is there a trick to force loading from the ruby_site directory? 有没有技巧可以强制从ruby_site目录加载? Rails 2.3.10 Rails 2.3.10

Thanks 谢谢

I'm still not sure why you're needing to do this (and I imagine there is a better way), but if this is your only option, then here goes... 我仍然不确定为什么需要这样做(我想有更好的方法了),但是如果这是您唯一的选择,那么这里...

Unlike gems which are just 'required', Rails loads plugins by running eval on the plugin's init.rb file (see here for 2.3.10 if you're interested). 与只是“必需”的gem不同,Rails通过在插件的init.rb文件上运行eval来加载插件(如果您有兴趣,请参见此处 2.3.10)。 The 'site_ruby' folder is in Rails' load path, but files in there will be treated as normal libraries, not plugins. “ site_ruby”文件夹位于Rails的加载路径中,但其中的文件将被视为普通库,而不是插件。

To change this, you can easily add to Rails' load paths in your app config: 要更改此设置,您可以在应用程序配置中轻松添加到Rails的加载路径:

config.plugin_paths << "/usr/lib/ruby/site_ruby/1.8"

I don't have any experience with building RPM packages, but if it's forcing you to build your app in such a brittle way, then is it really the best way to distribute it? 我没有构建RPM软件包的经验,但是如果它迫使您以如此脆弱的方式构建应用程序,那么它真的是分发它的最佳方法吗? Just a thought! 只是一个想法! :) :)

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

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