[英]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
看看文檔 -
如果您的意圖是在表格未填充的情況下顯示輸入表單,請嘗試以下操作:
controller do
def index
collection.size == 0 ? redirect_to(new_subscription_path) : super
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.