繁体   English   中英

如果未创建对象,活动管理员如何在索引页面上呈现表单

[英]active admin how to render form on index page if object not created

我无法理解我做错了什么。 如果订阅空白,我的代码将无法工作,但如果我从 rails c 创建它,一切正常...

# frozen_string_literal: true

ActiveAdmin.register Subscription do
  actions :index

  index do
    result = Subscriptions::GetPricing.call(admin: current_admin)
    if result.success?
      render partial: 'subscription_form', locals: { amount: result.plan.amount }
    else
      flash[:alert] = result.message
      render partial: 'subscription_errors'
    end
  end
end

现在我得到:还没有订阅。 简单的消息。 我希望保留所有样式、导航面板等默认设置,但在容器中应该存储我的部分代码。

我认为您正在尝试做的事情有点错误。 index do block主要是渲染视图级别。 如果你想覆盖控制器动作,你必须像下面那样做 -

controller do
 def index
   # your code here
 end
end

看看文档 -

https://activeadmin.info/8-custom-actions.html

https://activeadmin.info/3-index-pages.html

如果您的意图是在表格未填充的情况下显示输入表单,请尝试以下操作:

controller do
  def index
    collection.size == 0 ? redirect_to(new_subscription_path) : super
  end
end

暂无
暂无

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

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