升级到rails 3.2.1后如何处理供应商/插件
升级到rails3.2.1后,出现此警告:
You have Rails 2.3-style plugins invendor/plugins! Rails 4.0 中将删除对这些插件的支持。将它们移出并将它们捆绑到您的 Gemfile 中,或者将它们作为 lib/myplugin/* 和 config/initializers/myplugin.rb 折叠到您的应用程序中。有关更多信息,请参阅发行说明:http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released
我将插件移至供应商/插件中目录但我不知道如何编写 config/initializers/myplugin.rb 文件,并且谷歌找不到答案。
After upgrading to rails3.2.1,this warning occurs:
You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released
I move my plugins in vendor/plugins directory but i don't know how to write config/initializers/myplugin.rb file, and google can't find the answer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚写了一篇关于此的博客文章:如何将 Simple Rails 2.3 样式插件转换为 Rails 3.2
I just wrote a blog post on this: How to Convert Simple Rails 2.3 Style Plugins for Rails 3.2
我刚刚经历过这个,发现你只需要浏览每个插件来检查一些事情:
vendor/plugins
中删除。vendor/plugins
中的文件夹并移动它到lib/plugins
我遇到的一件事是,您需要手动要求所有这些插件。这是我创建并放置在 config/initializers/plugins.rb 中的初始化程序:
我还遇到了某些插件所需的初始化程序的问题,因此我将这些特定的初始化程序移至
lib/plugins/initializers
文件夹。您必须将它们命名为插件的名称,因此my_plugin
插件的初始化程序必须位于文件lib/plugins/initializers/my_plugin.rb
希望如此有帮助!
I just went through this and found that you just have to go through each plugin to check a few things:
vendor/plugins
vendor/plugins
and move it tolib/plugins
One thing I ran across is that you then need to require all those plugins manually. Here is the initializer I created and placed in
config/initializers/plugins.rb
:I also had the problem of initializers I needed for some of the plugins, so I moved those particular initializers into the
lib/plugins/initializers
folder. You have to name them the name of the plugin, so an initializer for themy_plugin
plugin would have to be in the filelib/plugins/initializers/my_plugin.rb
Hope this helps!
其他两个答案都很好并且似乎有效。
但是,如果您的插件由供应商/插件/.../lib 下的单个 .rb 文件组成,并且供应商/插件/.../init.rb 只是一个
那么您只需将单个文件复制到您的 lib 目录并将一个文件添加到 config/initializers 中,该文件需要 'yourpluginname'
这是一个使用acts_as_lated 插件的具体示例,该插件还不是一个 gem。
将vendor/plugins/acts_as_erated/lib/acts_as_erated.rb复制到lib/
使用以下内容创建文件config/initializers/acts_as_erated.rb...
需要“acts_as_lated”
删除供应商/插件/acts_as_erated
both the other answers are good and seem to work.
However if your plugin consists of a single .rb file under vendor/plugins/.../lib and the vendor/plugins/.../init.rb is just a
Then you can simply copy the single file to your lib directory and add a file to config/initializers that does a require 'yourpluginname'
Here is a concrete example using the acts_as_rated plugin which is not a gem yet.
copy vendor/plugins/acts_as_rated/lib/acts_as_rated.rb to lib/
create a file config/initializers/acts_as_rated.rb with the following...
require 'acts_as_rated'
delete vendor/plugins/acts_as_rated
没有人提到转换为 Railtie 或 Rails::Engine。
只需将所有 ruby 文件移至 gem 中 [使用捆绑 gem 来创建它以最小化摩擦]。
然后查看 Railtie 文档 [并找到您的目标 Rails 版本]:
https:// /apidock.com/rails/v3.2.13/Rails/Railtie
将旧插件 init.rb 转换为 Railtie 非常简单方式,它为您提供了通往 Rails 4+ 的途径。
有视图或控制器吗?,然后使用 Rails::Engine 代替。虽然从工作流程的角度来看,gems 中的引擎可能很复杂,但将插件转换为插件却相当简单。
帮自己一个忙,开始在 gem 中构建测试,而不是在 Rails 项目中。
No one has mentioned converting to a Railtie or Rails::Engine.
Just move all of your ruby files into a gem [use bundle gem to create it for minimal friction].
Then have a look at the Railtie docs [and find your target Rails version]:
https://apidock.com/rails/v3.2.13/Rails/Railtie
It's quite easy to just convert an old plugin init.rb to a railtie in this way, and it gives you a pathway to Rails 4+.
Got views or controllers?, then use a Rails::Engine instead. While engines in gems can be complicated from a workflow standpoint, converting a plugin to one is pretty trivial.
Do yourself a favor and start building tests right in the gem, instead of in the Rails project.