本文介绍了如何将ActiveAdmin控制器分成新文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在注册的ActiveAdmin模型中,我的 controller do 块现在看起来很大,因此我想将控制器零件放在其他文件中。

My controller do block in a registered ActiveAdmin model is starting to look big now so I would like to put the controller part in some other file.

有可能吗?新文件的名称和路径应该是什么?

Is that possible? What should be the new file's name and path?

谢谢

推荐答案

这是一个很好的问题,不幸的是,没有很好的答案。我倾向于将其他所有内容推送到单独的文件中,首先使用局部视图...

That's a great question and unfortunately there is no great answer. I tend to push everything else into separate files, first the views using partials...

show title: 'Order' do
  render 'show', context: self
end

form partial: 'form'

...然后。可以使用ActiveSupport :: Concern和,但我认为它并不令人满意。也许有一天我们会收到一个拉取请求,以引用用户提供的ResourceController子类,但尚未发生。 TL; DR ,如果提取部分和服务还不够。

...then the business logic using services. It is possible to extract controller methods using ActiveSupport::Concern, and ActiveAdmin does this internally but I don't find it satisfying. Maybe one day we'll have a pull request to reference a user supplied subclass of ResourceController but it hasn't happened yet. TL;DR use Concerns if extracting partials and Services are not enough.

这篇关于如何将ActiveAdmin控制器分成新文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:19