简体   繁体   English

如何解决Rails插件上不推荐的rake任务?

[英]How to solve rake tasks deprecation on the rails plugin?

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 :: Railtie和Rails :: Engine相反,您不应该从Rails :: Plugin继承。 Rails::Plugin is automatically configured to be an engine by simply placing inside vendor/plugins. 只需将Rails :: Plugin放置在供应商/插件内部,即可自动配置为引擎。 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. 由于此操作是自动完成的,因此您实际上无法在插件内部声明Rails :: Engine,否则将导致相同文件被加载两次。 This means that if you want to ship an Engine as gem it cannot be used as plugin and vice-versa. 这意味着,如果您想将引擎作为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. Rails插件中的rake任务已弃用,建议改用lib / tasks。 How to solve this? 如何解决呢? Can I just simply move the plugin's tasks to the lib/tasks? 我可以简单地将插件的任务移至lib / tasks吗?

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 然后耙rails:更新运行正常

If you're the developer of a plugin, you would simply move 如果您是某个插件的开发人员,则只需移动

my_cool_plugin/tasks

to

my_cool_plugin/lib/tasks

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

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