如何解决rails插件上的rake任务弃用问题?

时间:2022-05-31 22:28:17

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.

Rails :: Plugin只不过是一个Rails :: Engine,但由于它在启动过程中加载太晚,因此它没有与裸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.

与Rails :: Railtie和Rails :: Engine相反,你不应该继承Rails :: Plugin。通过简单地放置在供应商/插件内部,Rails :: Plugin自动配置为引擎。由于这是自动完成的,因此您实际上无法在插件中声明Rails :: Engine,否则会导致相同的文件被加载两次。这意味着如果您想将Engine作为gem发布,则不能将其用作插件,反之亦然。

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.

除了这个概念上的差异,Rails :: Engine和Rails :: Plugin之间的唯一区别是插件在引导过程中自动加载插件根目录下的文件“init.rb”。

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?

不推荐使用rails插件中的rake任务,建议使用lib / tasks。怎么解决这个?我可以简单地将插件的任务移动到lib / tasks吗?

2 个解决方案

#1


9  

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)

我刚刚遇到了同样的问题,只是将所有的vendor / plugin / * / tasks / *。rake文件移动到lib / tasks(必须创建这个目录,因为它不存在)

then rake rails:update ran fine

然后rake rails:update运行正常

#2


2  

If you're the developer of a plugin, you would simply move

如果您是插件的开发者,那么您只需移动即可

my_cool_plugin/tasks

to

my_cool_plugin/lib/tasks

#1


9  

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)

我刚刚遇到了同样的问题,只是将所有的vendor / plugin / * / tasks / *。rake文件移动到lib / tasks(必须创建这个目录,因为它不存在)

then rake rails:update ran fine

然后rake rails:update运行正常

#2


2  

If you're the developer of a plugin, you would simply move

如果您是插件的开发者,那么您只需移动即可

my_cool_plugin/tasks

to

my_cool_plugin/lib/tasks