如何解决 Rails 插件上的 rake 任务弃用问题?
由于此处引入的概念,
Rails::Plugin 只不过是一个 Rails::Engine,但由于它已加载 在启动过程中为时已晚,它确实 不具有相同的配置权力 作为一个裸露的 Rails::Engine。
与 Rails::Railtie 相对并且 Rails::Engine,你不应该这样做 继承自 Rails::Plugin。 Rails::Plugin 是自动的 只需简单地配置为一个引擎 放置在供应商/插件内部。自从 这是自动完成的,您 实际上不能声明一个 插件内的 Rails::Engine, 否则会导致同样的情况 文件被加载两次。这意味着 如果您想将引擎运送为 gem 它不能用作插件并且 反之亦然。
除了这个概念上的差异之外, 之间唯一的区别 Rails::Engine 和 Rails::Plugin 是 该插件会自动加载 插件根目录下的文件“init.rb” 在启动过程中。
Rails 插件中的 rake 任务已被弃用,建议使用 lib/tasks 代替。怎么解决这个问题呢?我可以简单地将插件的任务移动到 lib/tasks 吗?
Because of the concept introduced in here,
Rails::Plugin is nothing more than a
Rails::Engine, but since it's loaded
too late in the boot process, it does
not have the same configuration powers
as a bare Rails::Engine.Opposite to Rails::Railtie and
Rails::Engine, you are not supposed to
inherit from Rails::Plugin.
Rails::Plugin is automatically
configured to be an engine by simply
placing inside vendor/plugins. Since
this is done automatically, you
actually cannot declare a
Rails::Engine inside your Plugin,
otherwise it would cause the same
files to be loaded twice. This means
that if you want to ship an Engine as
gem it cannot be used as plugin and
vice-versa.Besides this conceptual difference,
the only difference between
Rails::Engine and Rails::Plugin is
that plugins automatically load the
file "init.rb" at the plugin root
during the boot process.
rake tasks in the rails plugins are deprecated and it is advised to use lib/tasks instead. How to solve this? Can I just simply move the plugin's tasks to the lib/tasks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚在这里遇到了同样的问题,只需将所有供应商/插件/*/tasks/*.rake 文件移至 lib/tasks (必须创建此目录,因为它不存在),
然后 rakerails:update 运行良好
i've just had the same problem here, just moved all the vendor/plugin/*/tasks/*.rake files to lib/tasks (had to create this directory because it didn't existed)
then rake rails:update ran fine
如果您是插件的开发人员,您只需
转到
If you're the developer of a plugin, you would simply move
to